searching using a combo box

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
 
J

Jeanette Cunningham

Try some debugging of that code to see what access gets for TonnageRange and
strWhere.
Set a breakpoint on this line
If Me.cboFilterTonnage = 1 Then

Step through the code line by line and see what values access gets by
hovering your mouse over strwhere, lnglen, me.filter.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top