Hi Professionals,
I have copied code from http://blogs.office.com/2012/05/03/using-a-combo-box-to-search-as-you-type/ and tried it to my Access program but not working as they mentioned. Can any body tell what is the wrong into the code and can give me access file after implementing it for demo.
Then in the Change event of the Combo Box, we add the following code:
If Nz(Me.cboFilter.Text) = “” Then
Me.Form.Filter = “”
Me.FilterOn = False
‘ If a combo box item is selected, filter for an exact match.
‘ Use the ListIndex property to check if the value is an item in the list.
ElseIf Me.cboFilter.ListIndex <> -1 Then
Me.Form.Filter = “[Company] = ‘” & _
Replace(Me.cboFilter.Text, “‘”, “””) & “‘”
Me.FilterOn = True
‘ If a partial value is typed, filter for a partial company name match.
Else
Me.Form.Filter = “[Company] Like ‘*” & _
Replace(Me.cboFilter.Text, “‘”, “””) & “*'”
Me.FilterOn = True
End If
‘ Move the cursor to the end of the combo box.
Me.cboFilter.SetFocus
Me.cboFilter.SelStart = Len(Me.cboFilter.Text)
End Sub
Your help will be highly appreciated.
Thanks
I have copied code from http://blogs.office.com/2012/05/03/using-a-combo-box-to-search-as-you-type/ and tried it to my Access program but not working as they mentioned. Can any body tell what is the wrong into the code and can give me access file after implementing it for demo.
Then in the Change event of the Combo Box, we add the following code:
Private Sub cboFilter_Change()
‘ If the combo box is cleared, clear the form filter.If Nz(Me.cboFilter.Text) = “” Then
Me.Form.Filter = “”
Me.FilterOn = False
‘ If a combo box item is selected, filter for an exact match.
‘ Use the ListIndex property to check if the value is an item in the list.
ElseIf Me.cboFilter.ListIndex <> -1 Then
Me.Form.Filter = “[Company] = ‘” & _
Replace(Me.cboFilter.Text, “‘”, “””) & “‘”
Me.FilterOn = True
‘ If a partial value is typed, filter for a partial company name match.
Else
Me.Form.Filter = “[Company] Like ‘*” & _
Replace(Me.cboFilter.Text, “‘”, “””) & “*'”
Me.FilterOn = True
End If
‘ Move the cursor to the end of the combo box.
Me.cboFilter.SetFocus
Me.cboFilter.SelStart = Len(Me.cboFilter.Text)
End Sub
Your help will be highly appreciated.
Thanks