Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check to see if table is empty

Status
Not open for further replies.

dnjacks

MIS
Feb 23, 2004
4
US
Is there a way I can check to see if a table is empty from code?
 
Select * from the table then see if the recordset is empty?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Warning (I got caught with this): if you use ADO the recordset counts don't work properly. You have to see if (BOF and EOF).

 
I was hoping there was a way to do this with out using a recordset. If anyone else has an idea, please share.
 
Why not use a recordset?
dim rs as new adodb.recordset, str as string
str = "Select count(*) as cnt from table"
rs.Open str, currentproject.connection

If rs(0) > 0 then
some records
else
no records
end if
Set rs = Nothing
 
If you don't like Recordset, you may try something like this:
If DCount("*", "myTableName") > 0 Then
MsgBox "Not empty"
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top