Design by Sue
Registered User.
- Local time
- Today, 12:46
- Joined
- Jul 16, 2010
- Messages
- 816
I have a search form that has 3 possible search fields, sID, sDescription and sProductGroup. The user can enter any amount of information in these fields and when they click the find button the resulting form displays all records that match any of the information entered, in any possible combination. (Based on the video found here http://www.datapigtechnologies.com/flashfiles/searchform.html) This part works 100% correctly, except that when there is not matching criteria (for example the user enters an sID as 500 but there is not matching record in the table for the ID and there is not other criteria entered in the form) the result is a blank form. This is not user friendly. I want to build into the search form a check for the entered information and give a message box that there is no matching records.
To that end I have found the following code works but if I am to do it this way, I will have to write 9 (I think that is the correct number) of If statements to cover all of the possibilities. I can do this but my fear is that I will miss one possible combination. So my question is - can someone suggest a better way to check these. It has to allow searches for any combination of entries and if the combination of these entries do not result in a match, then produce the message box.
If Me.sID.Value = "" And Me.sDescription.Value = "" And Me.sProductGroup.Value = "" Then
DoCmd.OpenForm "Item Master Edit 2 FRM", acNormal, , , , acNormal
Exit Sub
End If
If Not IsNull(Me.sID) And Me.sDescription.Value = "" And Me.sProductGroup.Value = "" And DCount("[ID]", "[Item Master TBL]", "[ID] = " & sID) = 0 Then
MsgBox "There are no items matching this criteria.", vbExplination, "No Items"
Exit Sub
End If
Thanks!
Sue
To that end I have found the following code works but if I am to do it this way, I will have to write 9 (I think that is the correct number) of If statements to cover all of the possibilities. I can do this but my fear is that I will miss one possible combination. So my question is - can someone suggest a better way to check these. It has to allow searches for any combination of entries and if the combination of these entries do not result in a match, then produce the message box.
If Me.sID.Value = "" And Me.sDescription.Value = "" And Me.sProductGroup.Value = "" Then
DoCmd.OpenForm "Item Master Edit 2 FRM", acNormal, , , , acNormal
Exit Sub
End If
If Not IsNull(Me.sID) And Me.sDescription.Value = "" And Me.sProductGroup.Value = "" And DCount("[ID]", "[Item Master TBL]", "[ID] = " & sID) = 0 Then
MsgBox "There are no items matching this criteria.", vbExplination, "No Items"
Exit Sub
End If
Thanks!
Sue