Syntax Question

D

dhstein

I can display a record count of a table like this:

MsgBox DBEngine(0)(0)!tblProduct.RecordCount

I'd like to put this statement in a function which will be passed the name
of the table as a string

Function CountRecords(TableName As String)

MsgBox DBEngine(0)(0)!TableName.RecordCount ' This syntax doesn't work

End Function

What syntax do I need here? Thanks for any help.
 
A

Allen Browne

Try:
MsgBox DBEngine(0)(0).TableDefs(TableName).RecordCount

It might be safer to use:
MsgBox DCount("*", tablename)
That should work for attached tables too.
 
D

dhstein

Chris O'C via AccessMonster.com said:
Use currentdb, not dbengine(0)(0) syntax to get the most up to date instance
of the db and its objects.

Function CountRecords(strTblName As String)
msgbox CurrentDb.TableDefs(strTblName).RecordCount
End Function

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top