Combobox / Filter

M

myxmaster

I have a combobox with the following code:
Private Sub Combo24_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Category] = " & Str(Nz(Me![Combo24], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

I have a field on my form called category that has:
Credit
Cash
Check
Safe Keeping

Using the combobox I would like the user to filter the form and show
only those records matching the cbox selection.
At present the following line is highlighted as an error:
rs.FindFirst "[Category] = " & Str(Nz(Me![Combo24], 0))

Other combobox 's that I have tried simply go to the selected record
but does not filter.

TIA
 
G

George Nicholson

Since its a string, you need to enclose the value from your form field in
single quotes:

rs.FindFirst "[Category] = '" & Str(Nz(Me![Combo24], 0)) & "'"


For clarity, here is the exact same statement with extraneous space added
between 's and "s:

rs.FindFirst "[Category] = ' " & Str(Nz(Me![Combo24], 0)) & " ' "



HTH
 
G

Guest

Is the category field of text data type? If so you'd need to wrap the value
in quotes:

rs.FindFirst "Category = """ & Me.Combo24 & """"

To filter the form rather than navigate to the first match set the form's
Filter and FilterOn properties:

Dim strFilter As String

strFilter = "Category = """ & Me.Combo24 & """"

Me.Filter = strFilter
Me.FilterOn = True

To clear the filter and show all records either use the built in button on
the forms toolbar, or set the FilterOn property to False, e.g. in the Click
event procedure of a 'Show All' button:

Me.FilterOn = False

Ken Sheridan
Stafford, England
 

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