473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

rs.recordcount is wrong

I've got a form pulling data from a table in the same database. The code below shows how the variables are set up. The problem is, the intRecs variable is 1, no matter how many rows I've got in the recordset. What am I doing wrong?
Expand|Select|Wrap|Line Numbers
  1. Dim dbs As Database
  2. Dim rs As Recordset
  3. Dim intRecs as Integer
  4. Dim intCounter as integer
  5.  
  6. Set dbs = CurrentDb
  7. Set rs = dbs.OpenRecordset("Select * from TodaysSalesReps")
  8.  
  9. intRecs = rs.RecordCount
  10. intCounter = 0
  11.  
  12. Do While intCounter < intRecs
Sep 21 '07 #1
4 10929
JKing
1,206 Expert 1GB
I've got a form pulling data from a table in the same database. The code below shows how the variables are set up. The problem is, the intRecs variable is 1, no matter how many rows I've got in the recordset. What am I doing wrong?

Dim dbs As Database
Dim rs As Recordset
Dim intRecs as Integer
Dim intCounter as integer

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("Select * from TodaysSalesReps")

intRecs = rs.RecordCount
intCounter = 0

Do While intCounter < intRecs
Hi, you need to move to the last record in the recordset before it will return the proper value. Give this a try.

Expand|Select|Wrap|Line Numbers
  1. Dim dbs As Database
  2. Dim rs As Recordset
  3. Dim intRecs as Integer
  4. Dim intCounter as integer
  5.  
  6. Set dbs = CurrentDb
  7. Set rs = dbs.OpenRecordset("Select * from TodaysSalesReps")
  8.  
  9. rs.MoveLast
  10. intRecs = rs.RecordCount
  11. intCounter = 0
  12.  
  13. Do While intCounter < intRecs
  14.  
Sep 21 '07 #2
FishVal
2,653 Expert 2GB
I've got a form pulling data from a table in the same database. The code below shows how the variables are set up. The problem is, the intRecs variable is 1, no matter how many rows I've got in the recordset. What am I doing wrong?
Expand|Select|Wrap|Line Numbers
  1. Dim dbs As Database
  2. Dim rs As Recordset
  3. Dim intRecs as Integer
  4. Dim intCounter as integer
  5.  
  6. Set dbs = CurrentDb
  7. Set rs = dbs.OpenRecordset("Select * from TodaysSalesReps")
  8.  
  9. intRecs = rs.RecordCount
  10. intCounter = 0
  11.  
  12. Do While intCounter < intRecs
Hi, there.

If you want to iterate records to the end of the recordset, you may use Recordset.EOF property.

Expand|Select|Wrap|Line Numbers
  1. While Not rs.EOF
  2. ............
  3. rs.MoveNext
  4. Wend
  5.  
Sep 21 '07 #3
I have a database that forcasts dates for each record in Tasks table and this is the code I use:

Expand|Select|Wrap|Line Numbers
  1.   Dim dbs As Database, rst As Recordset
  2.   Dim staTotal
  3.   Set dbs = CurrentDb
  4.   Set rst = dbs.OpenRecordset("Tasks")
  5.   staTotal = rst.RecordCount
  6.   For Reza = 1 To staTotal
  7.     SetupVer                              ' -------------------------- This is the loop out
  8.     DoCmd.GoToRecord , , acNext
  9.   Next Reza
  10.   rst.Close
  11.   Set dbs = Nothing
  12.  
So staTotal contains the number of records. I would use the following code (change as needed):

Expand|Select|Wrap|Line Numbers
  1.   Dim dbs As Database, rst As Recordset
  2.   Dim staTotal
  3.   Set dbs = CurrentDb
  4.   Set rst = dbs.OpenRecordset("Tasks")
  5.   staTotal = rst.RecordCount
  6.   rst.Close
  7.   Set dbs = Nothing
  8.  
Sep 21 '07 #4
Thanks. I went with the rs.Movelast option. This works perfectly:

Expand|Select|Wrap|Line Numbers
  1. Dim dbs As Database
  2. Dim rs As Recordset
  3. Dim intCounter As Integer
  4. Dim intRecs As Integer
  5.  
  6. Set dbs = CurrentDb
  7. Set rs = dbs.OpenRecordset("Select * from TodaysSalesReps")
  8.  
  9. rs.MoveLast
  10. intRecs = rs.RecordCount
  11. intCounter = 0
  12. rs.MoveFirst
  13.  
  14. Do While intCounter < intRecs
Sep 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jeff Boyer | last post by:
Hello everyone, Can someone tell me why a ADO recordset.recordcount would return a -1? I have confirmed that it has records in it by writing some values to the screen. Why can't I count the...
12
by: scott | last post by:
In LISTING 2, I have a SPROC that returns a recordset and a recordcount in SQL QA. I can access the Recordset with no problem. How can I grab the Recordcount with ASP code at the same time I'm...
2
by: nick_faye | last post by:
why does my recordcount returns the # of actual records + 1? btw, i am using ms access. i don't know what happened but at first, my table seems ok. the recordcount returns the correct # of...
3
by: nkechifesie | last post by:
I want my form to display the absolute position and the recordcount of the records in the database but it keeps shoing me -1 for both . Why? this is the code Private Sub MnuOVehType_Click()...
3
by: indhu | last post by:
hi table:shot dim storyboard as ADODB.recordset recordcount shld populate in textbox. panel: A, B C,D(am using combobox) Noofpanel=4txtbox or label is this possible.
1
by: qqmbers | last post by:
May be it will help someone. I faced the strange problem with RecordCount property of cloned Recordset within the Current event handler. The RecordCount value was correct every time I had...
4
by: jaishu | last post by:
Hi all, I am in the process of developing a small Access application. i have the table locally in Access and I am using the following code to get the recordcount ( or to check if any record...
6
by: shank | last post by:
I switched to parameterized queries and now having issues with RecordCount. Regardless of the records returned, RecordCount = -1 How do I get an actual count? thanks <% Dim rsProdCount__OD...
3
by: sparks | last post by:
Is recordcount a little messed or what? For Each tdf In dbs.TableDefs If Left(tdf.Name, 3) = "tbl" Then Debug.Print tdf.Name Debug.Print tdf.RecordCount it prints the correct name but the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.