Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old May 9th, 2008, 08:36 AM
kryles kryles is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 80 kryles User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 6 m 45 sec
Reputation Power: 1
VBA - Rst.recordcount

Hi,

I use openRecordset and then RecordCount but it only seems to be counting the first record. I've used this method before so I can't seem to catch what is going wrong.

DETAIL TABLE
==========

Customernumberunique - text
productID - text
OrderNo - text

ACTUAL DATA
==========

727490,727490- 1134000000,CAN624576
727490,727490- 0231000000,CAN624576
727490,727490- 0440ME0000,CAN624576
727490,727490- 0276000000,CAN624576

Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("SELECT * FROM [Detail] WHERE [OrderNo] = 'CAN624576'", dbOpenDynaset)
MsgBox (rst.RecordCount) 'only gets 1 instead of 4
MsgBox (rst("Customernumberunique")) '727490- 1134000000


My understanding was recordcount would have 4, I go to rst.movefirst, then loop through for all records.

Am i missing something here?

Thanks,

Reply With Quote
  #2  
Old May 9th, 2008, 09:03 AM
AOG123's Avatar
AOG123 AOG123 is offline
Registered Hero
ASP Free Novice (500 - 999 posts)
 
Join Date: Oct 2006
Posts: 866 AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level)AOG123 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 20 h 52 m 33 sec
Reputation Power: 946
Try,

Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("SELECT * FROM [Detail] WHERE [OrderNo] = 'CAN624576'", dbOpenDynaset)

rst.MoveLast

MsgBox (rst.RecordCount) 'only gets 1 instead of 4
Comments on this post
kryles agrees: much appreciated

Reply With Quote
  #3  
Old May 9th, 2008, 09:08 AM
kryles kryles is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 80 kryles User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 6 m 45 sec
Reputation Power: 1
Is that normal that it needs to actually go through them to count them? I thought a recordset was a copy, so wouldn't it have counted while copying?

btw yes that did get the count

Reply With Quote
  #4  
Old May 9th, 2008, 09:17 AM
mehere's Avatar
mehere mehere is online now
Senior Sarcasm Wizardess
Click here for more information.
 
Join Date: Feb 2005
Location: Dreamland
Posts: 12,483 mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 10976 Folding Title: Novice Folder
Time spent in forums: 4 Months 3 Weeks 3 Days 21 h 7 m 11 sec
Reputation Power: 1450
here's some info regarding RecordCount
Quote:
RecordCount without MoveLast
For recordsets based on queries, SQL statements, and attached tables, the RecordCount property returns the number of records accessed so far. When you first OpenRecordset(), Access grabs the first record, and keeps processing your code while the others load. So, if you test RecordCount immediately after you OpenRecordset, you typically get 0 (if there are no records), or 1 (if there are any, regardless of how many will load.) This does not apply to recordsets of type dbOpenTable type (the default for local tables.)

Solution:
If you need to know the RecordCount, use the MoveLast method first. This forces Access to wait while all records load, so the RecordCount reflects the entire recordset.

Hint:
Don't MoveLast unless you really need to: this will be slow with a large recordset or a recordset drawn across a network. RecordCount will always be at least 1 if records exist, so there is no need to MoveLast if you only want to know if you have records to work with.


you can also have a look at VBA Traps: Working with Recordsets
__________________
Come JOIN the party!!!

Quote of the Month:
Trouble: Luck can't last a lifetime unless you die young.

Questions to Ponder:
Do cemetery workers prefer the graveyard shift?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright© 2008 sbenj69

Last edited by mehere : May 9th, 2008 at 09:19 AM.

Reply With Quote
  #5  
Old May 9th, 2008, 10:15 AM
kryles kryles is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 80 kryles User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 6 m 45 sec
Reputation Power: 1
much appreciated, thanks for the help guys

Ill keep that link just for future reference in case I come across this in distant future and forget lol.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > VBA - Rst.recordcount


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway