Link to home
Start Free TrialLog in
Avatar of pdvsa
pdvsaFlag for United States of America

asked on

No Data and a Form

Experts,

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
Avatar of hello_everybody
hello_everybody
Flag of South Africa image

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


http://www.pcreview.co.uk/forums/no-data-form-open-t3987721.html
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<<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.

JimD.
Avatar of pdvsa

ASKER

Perfect.  thank you