Filter Form with Combo Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have read numerous threads on this subject but nothing has worked for me
yet. I am using Access 2003.

My current code for the combo box named ProgramFilter is:

Private Sub ProgramFilter_AfterUpdate()
Dim sProgram
With ProgramFilter
If .ListIndex <> -1 Then
sProgram = .Column(.BoundColumn - 1)
Me.Filter = "[Program] = sProgram"
Me.FilterOn = True
MsgBox "Filter Applied"
End If
End With
End Sub

The filter part works but it isn't setting the combo box choice as the value
of sProgram. I only get a dialog box that pops up saying "Enter Parameter
Value". If I enter a valid value the form is filtered correctly, but I want
the combo box to set the parameter value as is intended.

Thank you for any guidance you can provide.
 
Your filter statement is passing in the string sProgram rather than the value
contained in the variable. Change it to:
Me.Filter = "[Program] = " & sProgram

Barry
 
Oops. Amendment:

Me.Filter = "[Program] = '" & sProgram & "'"

This assume the data contained in this column is a string. Notice the extra
single quotes.

Barry Gilbert said:
Your filter statement is passing in the string sProgram rather than the value
contained in the variable. Change it to:
Me.Filter = "[Program] = " & sProgram

Barry

Ryan said:
I have read numerous threads on this subject but nothing has worked for me
yet. I am using Access 2003.

My current code for the combo box named ProgramFilter is:

Private Sub ProgramFilter_AfterUpdate()
Dim sProgram
With ProgramFilter
If .ListIndex <> -1 Then
sProgram = .Column(.BoundColumn - 1)
Me.Filter = "[Program] = sProgram"
Me.FilterOn = True
MsgBox "Filter Applied"
End If
End With
End Sub

The filter part works but it isn't setting the combo box choice as the value
of sProgram. I only get a dialog box that pops up saying "Enter Parameter
Value". If I enter a valid value the form is filtered correctly, but I want
the combo box to set the parameter value as is intended.

Thank you for any guidance you can provide.
 
Thank you very much Barry. I can leave work now feeling that I accomplished
at least a little bit.

I had to change the line for setting the variable to:
sProgram = .SelText

But the line of code you provided otherwise did the trick. I don't think I
would have ever gotten the syntax right on my own. The purpose for the
single-quotes, double-quotes, and &s eludes me completely. But it obviously
is needed.


Barry Gilbert said:
Oops. Amendment:

Me.Filter = "[Program] = '" & sProgram & "'"

This assume the data contained in this column is a string. Notice the extra
single quotes.

Barry Gilbert said:
Your filter statement is passing in the string sProgram rather than the value
contained in the variable. Change it to:
Me.Filter = "[Program] = " & sProgram

Barry

Ryan said:
I have read numerous threads on this subject but nothing has worked for me
yet. I am using Access 2003.

My current code for the combo box named ProgramFilter is:

Private Sub ProgramFilter_AfterUpdate()
Dim sProgram
With ProgramFilter
If .ListIndex <> -1 Then
sProgram = .Column(.BoundColumn - 1)
Me.Filter = "[Program] = sProgram"
Me.FilterOn = True
MsgBox "Filter Applied"
End If
End With
End Sub

The filter part works but it isn't setting the combo box choice as the value
of sProgram. I only get a dialog box that pops up saying "Enter Parameter
Value". If I enter a valid value the form is filtered correctly, but I want
the combo box to set the parameter value as is intended.

Thank you for any guidance you can provide.
 
Back
Top