How to determine if table contains no records?

G

Guest

Hello,

I use the following code to determine if tblTable exists before using it later. But the code is not enough because the table could be empty. How do I check if the tblTable has no data? Or is empty? Contains no records? Thanks,

RichardA

Dim dbs As Database
Dim tdf As TableDef
Dim blnTableExists As Boolean

'Determine if a table exists.
blnTblExists = False
Set dbs = CurrentDb()
For Each tdf In dbs.TableDefs
If tdf.Name = "tblTable" Then blnTableExists = True
Next tdf

If (blnTableExists = False) Then 'Do not access tblTable
GoTo 10
End If
 
G

Guest

Use RecordCount, like:

currentdb.TableDefs("AllData").RecordCount

If = 0 then it is empty.
 

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