Dingo212
asked on
If statement for VBA Access
Hello,
I have 3 boxes/fields in a search form. I can perform a search by filling out 1 field, 2 fields or all 3 of them.
The fields are
1 combo box (I can select a country, say Canada and get the search filtering all Canadian records)
2 text boxes (I can type in a keyword to get the search boxes brings in results too)
Now if I don't type/choose in anything at all from these 3 fields, my program kinda crashes/goes in to debug.
What I want is few lines of code to check if anything is entered (using AND) and if not I want a message displayed saying something like "you must have at least 1 criteria to search"
And then stop there.
what I have so far is this but I think I am wrong here considering I did little VB coding way back.
If IsNull(txtSearchField1) AND isNull(txtSearchField2) AND IsNull(cboSearchField1) Then
MsgBox "you must have at least 1 criteria to search"
Else
<<I believe my rest of the search code goes here?>>
End If
Thanks for the help!
I have 3 boxes/fields in a search form. I can perform a search by filling out 1 field, 2 fields or all 3 of them.
The fields are
1 combo box (I can select a country, say Canada and get the search filtering all Canadian records)
2 text boxes (I can type in a keyword to get the search boxes brings in results too)
Now if I don't type/choose in anything at all from these 3 fields, my program kinda crashes/goes in to debug.
What I want is few lines of code to check if anything is entered (using AND) and if not I want a message displayed saying something like "you must have at least 1 criteria to search"
And then stop there.
what I have so far is this but I think I am wrong here considering I did little VB coding way back.
If IsNull(txtSearchField1) AND isNull(txtSearchField2) AND IsNull(cboSearchField1) Then
MsgBox "you must have at least 1 criteria to search"
Else
<<I believe my rest of the search code goes here?>>
End If
Thanks for the help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can force a default for a combo box by using the following on the on open event of your form:
cboSearchField1 = cboSearchField1.column(0,0
This sets the combo box to the first value in it's list and therefore prevents your user doing an invalid search....