View Full Version : Search forms


Neilw
04-24-2002, 02:14 AM
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.

Geoff Codd
04-24-2002, 02:48 AM
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).]

Neilw
04-24-2002, 03:38 AM
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!

spalmateer
04-24-2002, 02:39 PM
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).]