Testing for Last Record

G

Gibson

Is there a way to test if there is a current record of if the table is
empty? I am using the following code behind an OnClick event to delete a
record in a table.

If Not Me.NewRecord Then
intResponse = MsgBox("Are you sure you want to delete Line?",
vbQuestion + vbYesNo, "Delete Line")
If intResponse = vbYes Then
RunCommand acCmdDeleteRecord
RunCommand acCmdRecordsGoToLast
End If
End If

After I delete the record I would like to test to see if I just deleted the
last record in the table and if so do something. Is there way to test to
see if no more records exist in the table?
 
A

Allen Browne

There are no records in a form if:
(Me.CurrentRecord = 1) And (Me.NewRecord)
An alternative approach:
Me.RecordsetClone.RecordCount = 0

However, that could be because it is filtered, or in data entry mode.
There are no records in the table if DLookup() on the primary key of the
table produces null, e.g.:
IsNull(DLookup("ID", "Table1"))
 

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