K
kenista
I have been putting together a search form for my database, and thought that
it would be useful for the users to pick from a combo box to search for their
required field.
I have read Allan Browne's notes on the search form
http://allenbrowne.com/ser-62.html
but have not had any luck being able to search so far. It just returns with
an error box saying 'no criteria'.
My code is as follows:
Private Sub cmdFilter_Click()
If Me.cboFilterTonnage = 1 Then
StrWhere = StrWhere & "([TonnageRange] = True) AND "
ElseIf Me.cboFilterTonnage = 0 Then
StrWhere = StrWhere & "([TonnageRange] = False) AND "
End If
'See if the string has more than 5 characters (a trailing " AND ") to remove.
lngLen = Len(StrWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND
" at the end.
StrWhere = Left$(StrWhere, lngLen)
'For debugging, remove the leading quote on the next line.
'Debug.Print strWhere
'Finally, apply the string as the form's Filter.
Me.Filter = StrWhere
Me.FilterOn = True
End If
End Sub
it would be useful for the users to pick from a combo box to search for their
required field.
I have read Allan Browne's notes on the search form
http://allenbrowne.com/ser-62.html
but have not had any luck being able to search so far. It just returns with
an error box saying 'no criteria'.
My code is as follows:
Private Sub cmdFilter_Click()
If Me.cboFilterTonnage = 1 Then
StrWhere = StrWhere & "([TonnageRange] = True) AND "
ElseIf Me.cboFilterTonnage = 0 Then
StrWhere = StrWhere & "([TonnageRange] = False) AND "
End If
'See if the string has more than 5 characters (a trailing " AND ") to remove.
lngLen = Len(StrWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND
" at the end.
StrWhere = Left$(StrWhere, lngLen)
'For debugging, remove the leading quote on the next line.
'Debug.Print strWhere
'Finally, apply the string as the form's Filter.
Me.Filter = StrWhere
Me.FilterOn = True
End If
End Sub