Counting Records in a table

catbeasy

Registered User.
Local time
Today, 03:58
Joined
Feb 11, 2009
Messages
140
Access 97..

I am trying to write code that will count the number of records in table, but it appears that I'm getting the syntax incorrect as I keep getting a Type Mismatch error. The code is:

Dim d As Database
Dim tdf As TableDef

str_obj_name = "table_data"

Set tdf = d.TableDefs(str_obj_name)

If tdf.RecordCount > 0 Then
MsgBox "There is at least one record in the table"
Else
MsgBox "There are no records in the table"
End If

Any suggestion as to what I'm doing wrong is appreciated..
 
Why not just use dcount?

I could try that. What are the advantages of using Dcount over the method I was trying?

Is one or the other a better practice due to memory or speed of processing?

Thanks..
 
Users sometimes shy away from domain functions because of speed but in this case I'd say it's fine to use it. The times I have stayed away is where it'd be convenient to use it in a query where you might call it thousands of times (say once for each row), then it can slow things down.
 

Users who are viewing this thread

Back
Top Bottom