How to prevent a form open if no records to show?
Sometimes it is necessary to prevent a form open if there are records to show, for example when doing a query and no registration is not required, we do not need to be open form since we have no data to display. So what we have to check is whether there are records to show and if there is no show a message and impede the form open. How?
It's easy to just put the code below in the form properties in the event 'to open':
= 0 Then If Form.RecordsetClone.RecordCount
MsgBox "No records found.", VbExclamation, "Error!"
DoCmd.Close acForm, "find data"
Exit Sub
End If
To see an example download: Prevent Form Open






























The example presented is excellent.
I agree with the previous review!
Simple and efficient!
Thank you!