How To Display Message "No Records Found" In Forms

K

Ktowner

I have a Database (Access 07) that I put to gather and use to help manage a
large equipment fleet for the DOT. I have never had any formal training in
Access but through trial and error and exploring sample databases have built
a very useful DB.
I have a form that opens from a query. I would like a message to display
when the query returns 0 records to the form. I explored the previous
questions on this post and found the following code that I used.

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
End If
End Sub

This stops the form from opening when 0 records are returned. What else do
I need to add to the code to display a message “No Records Found†and return
back to my forms switchboard?

Thanks in advance

Don K.
 
J

John Spencer

Try the following.

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No records found.",vbInformation,"No Records")
Cancel = True
End If
End Sub


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

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