Simple: Count number of Records (2 Viewers)

e2cheng

Registered User.
Local time
Today, 05:11
Joined
Dec 13, 2002
Messages
72
I'm trying to count the number of records in a query, form and report. Theoretically, the method should be identical. But I'm having major issues sorting this out. I've tried searchin gprevious forum, but don't really understand how to implement things such as the

.count property
Recordset..... property
currentrecord.count property
etc.

just really confused. I also found this thing on the MS help menu that gave me step by step instructions for displaying this in a text box. only problem, they wanted me to set the RunningCount property to something.. i forgot, just confused now...

Thank you in advance for any help! very much appreciated
 

sambo

Registered User.
Local time
Today, 01:11
Joined
Aug 29, 2002
Messages
289
Code:
Dim db As DAO.Database, rst As DAO.Recordset, recNum As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset("YourTableQueryName", vbOpenDynaSet)

rst.MoveLast
rst.MoveFirst  'Populate the recordset
recNum = rst.RecordCount  'count the Records
MsgBox recNum
 
Last edited:

e2cheng

Registered User.
Local time
Today, 05:11
Joined
Dec 13, 2002
Messages
72
sambo to the rescue again!

hi sambo,

thank you very much for your reply again... i tried just cutting and pasting and i'm getting this error msg..

method or data member not found. and it's refering to the rst.MoveLast record.. I'm not sure what that's supposed to mean, am i missing a library somewhere???

all i did was replace your "YourTableQueryName" to the name of my current form. i'm using this code on the form oload you think that might be a problem as well??

thanx again!

eric
 

sambo

Registered User.
Local time
Today, 01:11
Joined
Aug 29, 2002
Messages
289
A form is not a Recordset..
Recordsets are either queries or tables.

If you want to use your form's recordset try this...

Set rst = Forms!YourFormName.Form.RecordsetClone

Instead of this..

Set rst = db.OpenRecordset("YourTableQueryName", vbOpenDynaSet)
 

e2cheng

Registered User.
Local time
Today, 05:11
Joined
Dec 13, 2002
Messages
72
ok, i've tried changing that line of code and putting in my form name there. but i still get the same error.

so i went back tot eh original and ran the code with it referencing a query, but i still get that error...

not sure what's happening in this function...

thank you for your patience and help
 

sambo

Registered User.
Local time
Today, 01:11
Joined
Aug 29, 2002
Messages
289
Go to Tools->References...
Make sure DAO 3.6 is checked.
This allows you to use the DAO library
 

sambo

Registered User.
Local time
Today, 01:11
Joined
Aug 29, 2002
Messages
289
Whoops..

Put in dbOpenDynaSet instead of vbOpenDynaSet
 

Mile-O

Back once again...
Local time
Today, 09:11
Joined
Dec 10, 2002
Messages
11,316
Just one thing I noticed in Sambo's code example.

Code:
Dim db As DAO.Database, rst As DAO.Database, recNum As Integer

You have rst dimensioned as a database and not a recordset.
 

sambo

Registered User.
Local time
Today, 01:11
Joined
Aug 29, 2002
Messages
289
DOH!!

That would probably do it too... :D
I'll fix that for future viewers.
 

e2cheng

Registered User.
Local time
Today, 05:11
Joined
Dec 13, 2002
Messages
72
thank you all!

thank you all for your help. i get it.. much appreciated!
 

sambo

Registered User.
Local time
Today, 01:11
Joined
Aug 29, 2002
Messages
289
Sorry about the fat fingers.. :rolleyes:
 

e2cheng

Registered User.
Local time
Today, 05:11
Joined
Dec 13, 2002
Messages
72
referencing

hi, sorry to bother again, but let's say i put the code in a function

Code:
Public Function recNum(objectName As String) As Integer
    Dim db As DAO.Database, rst As Recordset

    Set db = CurrentDb
    'Set rst = db.OpenRecordset("qryDynamic_QBF", dbOpenDynaset)

'*************************************
    Set rst = objectName & .Form.RecordsetClone
'*************************************
    rst.MoveLast
    rst.MoveFirst  'Populate the recordset
    recNum = rst.RecordCount  'count the Records
End Function

what is the proper way to attach my objectName variable in front of .Form.RecordsetClone .

Thank you once again for your patience..

Sincerely,
Eric
 

sambo

Registered User.
Local time
Today, 01:11
Joined
Aug 29, 2002
Messages
289
Currently, you have it set up to only return the recordset from a form (not tables or queries), so why don't you just change your parameter from an object to a form data type.

Instead of..
Public Function recNum(objectName As String) As Integer

Try..
Public Function recNum(frm As Form) As Integer

Set rst = frm.Form.RecordsetClone


Here is the new Function Call...
tempNum = recNum(Forms!YourForm)
MsgBox tempNum
 

e2cheng

Registered User.
Local time
Today, 05:11
Joined
Dec 13, 2002
Messages
72
hi sambo,

thank you so much again. don't know how much you've helped! passing in a form, ingenius... i will have to explore more.. but for now, it's time to get some rest.

extremely grateful,
eric
 

Users who are viewing this thread

Top Bottom