If 0 Records In Table...

  • Thread starter Thread starter Bonnie
  • Start date Start date
B

Bonnie

Using A02. I have an OnClick event procedure that runs a
macro with a series of queries that include 'make backup
of ConfirmTable' (save records temporarily, just in
case), 'append all' (to archive table) and 'delete
all'(from ConfirmTable) in order to clear ConfirmTable
each day for new entries (after running a few reports).

How can I get the procedure to stop if ConfirmTable is
already empty? (In case someone else tries to run it, they
copy (make backup) of an empty table and the original
backup is then also empty. Should that be code or in the
macro?

Thanks in advance for any help or advice!!!
 
I use this function. Maybe somebody else has an easier way..

Public Function TableEmpty(TableName As String) As Boolean
' tests whether the table is empty

Dim dbs As ADODB.Connection, rst As ADODB.Recordset
Dim FindResult As Boolean

Set dbs = CurrentProject.Connection ' open the database
Set rst = New Recordset ' open a recordset

' open the the table
rst.Open TableName, dbs, adOpenStatic, adLockReadOnly


If (rst.RecordCount > 0) Then ' see if there are any rows in this table
FindResult = False
Else
FindResult = True
End If
' close everything rst.Close
dbs.Close
Set dbs = Nothing
Set rst = Nothing

TableEmpty = FindResult

End Function
 
Thanks to both but I'll go with the shorter one. It works
GREAT!!! Can I use it for query names same as table names?
The asterisk means 'all'?

Thank you for taking the time to help folks like me that
are learning on our own. I REALLY appreciate it.
 
Back
Top