No Data and a Form


I see that a form does not have a "On No Data" event like a report has.  
How can I craft an On No Data for a  form?

thank you.

this is what I use for a report:
Private Sub Report_NoData(Cancel As Integer)

    MsgBox "No Data"
    Cancel = True
End Sub
pdvsaProject financeAsked:
Who is Participating?
Jim Dettman (Microsoft MVP/ EE MVE)Connect With a Mentor PresidentCommented:

In the forms OnLoad event you could do:

  If Me.recordsetclone.RecordCount = 0 then
     Msgbox "No data"
     Docmd.close  acForm, Me.Name
  End If

you can check recordset count on form's open event, and cancel it:

if Me.Recordset.RecordCount = 0 then
Cancel = true
end if

DoCmd.OpenForm in that case will produce runtime error which you have to handle
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<on form's open event>>

  Really don't want to use OnOpen for this; that's a little too early and might be hit or miss.  Your not guaranteed that the forms recordset has been loaded until you hit OnLoad.

pdvsaProject financeAuthor Commented:
Perfect.  thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.