milkman2500
Registered User.
- Local time
- Today, 11:38
- Joined
- Oct 21, 2012
- Messages
- 45
Hi,
I'm attempting to filter my form with combo boxes. I've added the below code, but the if statement that checks if one of the combo boxes is null won't work. If the combo box is null or "", it's supposed to assign a wildcard to the variable. But it doesn't pass the test and goes straight to the Else statement. I've highlighted the if statement that keeps failing in red.
I'm attempting to filter my form with combo boxes. I've added the below code, but the if statement that checks if one of the combo boxes is null won't work. If the combo box is null or "", it's supposed to assign a wildcard to the variable. But it doesn't pass the test and goes straight to the Else statement. I've highlighted the if statement that keeps failing in red.
Code:
Private Sub btn_Search_Click()
'create variables to store the combo box values
Dim str_Country As String
Dim str_Vendor As String
Dim str_Survey As String
'If any of the combo boxes are left blank, assign wild card to their value.
If cbo_Country.Value = "" Or Null Then
str_Country = "*"
Else
str_Country = cbo_Country.Value
End If
If cbo_Survey_Vendor.Value = "" Or Null Then
str_Vendor = "*"
Else
str_Vendor = cbo_Survey_Vendor.Value
End If
[COLOR=red]If cbo_Survey_Title.Value = "" Or Null Then
str_Survey = "*"
Else
str_Survey = cbo_Survey_Title.Value
End If[/COLOR]
MsgBox ("Country like " & str_Country & ", Vendor like " & str_Vendor & ", Survey like " & str_Survey)
'filter the form according to the combo box values.
Me.Form.Filter = "[Country] Like '" & str_Country & "'" & _
"And [Survey_Vendor_Name] Like '" & str_Vendor & "'" & _
"And [Survey_Name] Like '" & str_Survey & "'"
Me.FilterOn = True
End Sub 'btn_Search_Click()