Search forms

Neilw

Registered User.
Local time
Today, 22:23
Joined
Mar 13, 2002
Messages
36
I have a search form which uses queries to open a form so it is filtered accoring to the users input. However, when no matches are found it just opens a blank form. Is it possible to make it display a message box instead? Saying that no matches are found.

Thanks.
 
on the form you could put some code on the on load event like

if isnull(Me![FieldName]) then
Msgbox" There are no matching records"
DoCmd.Close acForm, "FormName", acSaveNo
EndIf

[This message has been edited by Geoff Codd (edited 04-24-2002).]
 
Thanks geoff, problem then is that when the form is opened for the first time to put the first record in, it will give the message and close!
 
Use DCount to find out how many records are in the query before you open the form. Use this code on your command button (on click) that opens the form.

If DCount("*", "qrySearch") < 1 Then
MsgBox "There are no records that matched your criteria!", vbCritical, "No Matching Records"
Me.txtYourField.SetFocus
Exit Sub
Else: DoCmd.OpenForm "frmSearch"
End If

HTH
Scott

[This message has been edited by spalmateer (edited 04-24-2002).]
 

Users who are viewing this thread

Back
Top Bottom