How to prevent a form open if no records to show?

Posted on Saturday, May 2, 2009 - 11:32 | by admin |

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

RSS feed | Trackback URI

2 Comments »

Comment by Augusto Tolentino
2010-08-17 13:48:21

The example presented is excellent.

Comment by Armando
2011-01-27 00:50:58

I agree with the previous review!

Simple and efficient!

Thank you!

Name (required)
Email (required - not published)
Website
Your comment ( Decrease | Increase )
You can use <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <b> <cite> <code> <del datetime=""> <em> <i> <Q cite=""> <strike> <strong> in the comments.

Presentation

Avatar

Thank you for visiting.
Subscribe to feed not to miss any messages.

Here in blog I will provide examples of working with Microsoft Access and also ask questions to those who ask. More

Want to subscribe?

Subscribe or subscribe by email:
Enter your email:


Ads