Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to not open an empty form

Status
Not open for further replies.

Davide77

Technical User
Mar 6, 2003
166
0
0
CH
I have some form that need a input from the user to be opened. The input is a find question and the user write a text that will be found in the records of the mask. The problem is that it open the forms also when it is empty. I would like to show a messagebox like "Nothing found" instead of the empty form. How can I do this?
 
hi there
in the open event of the form there is a "Cancel" variable, that when set to non zero value , cancels the opening of the form.
so have your check there, and if you want the form not to open, set cancel=1
something like:

Private Sub Form_Open(Cancel As Integer)
If [whatever you want to check here] Then
MsgBox "Your search did not find ant records."
Cancel = 1
End If
End Sub

good luck
Erez.
 
You need to test for the presence of records in your query before you open your form, then use if logic to open a message box if there are none. This technique runs the query twice, once for the test and once for the recordset, but that should not be an issue except for very large db's.

1 - Design a query (qryYourQry) that will test for the presence of a record meeting the criteria entered by your user

2 - The DCount below will run the query and count the records that match the criteria. Based on that, you can decide the appropriate actions for when matching records exist and when none exist.

- - -

If DCount("*", "qryYourQry") > 0 Then
'Do whatever when you have at least one match

Else
'Do whatever when there is no match

End If
- - - -

Bryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top