0

I am trying to filter a subform with a combobox. What I have works, but it keeps bringing up an "Enter Parameter Value" textbox. When I enter the value I want to filter with, it searches the subform no problem. I would prefer to not have to enter the value though as it defeats the purpose of the combobox.

Here is my code for the ComboBox,

    Private Sub ComboFE_AfterUpdate()

    On Error GoTo Proc_Error
If IsNull(Me.ComboFE) Then
   Me.SubFormPF.Form.Filter = ""
   Me.SubFormPF.Form.FilterOn = False
Else
  Me.SubFormPF.Form.Filter = "Lead_FE = " & Me.ComboFE
  Me.SubFormPF.Form.FilterOn = True
End If
Proc_Exit:
   Exit Sub
Proc_Error:
   MsgBox "Error " & Err.Number & " in setting subform filter:" & vbCrLf & Err.Description
   Resume Proc_Exit

End Sub

I have checked and made sure all the names are correct and match the corresponding items on my form.

Any Ideas? Many Thanks

Ethan
  • 51
  • 9

1 Answers1

0

When applying a filter on a text column, the value needs quotes.

Me.SubFormPF.Form.Filter = "Lead_FE = '" & Me.ComboFE & "'"

To avoid problems if the value itself contains quotes, use Gustav's CSql() function from here: https://stackoverflow.com/a/36494189/3820271

Me.SubFormPF.Form.Filter = "Lead_FE = " & CSql(Me.ComboFE.Value)

This works for all data types.

Andre
  • 26,751
  • 7
  • 36
  • 80