Apply filter based on the value of a field

G

Guest

Hello -

I have the following Procedure:

Private Sub Course_IDFilter_Exit(Cancel As Integer)
Dim StringWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to
append to.


Me.Filter = "[Course_ID]=[Course_IDFilter]"
Me.FilterOn = True

End Sub

The objective is to apply a filter to the data in the detail section of a
form for all records with [Course_ID] = to the number in the unbound
[Course_IDFilter] field after a course ID is entered into it.

The filter works, but I get an "Enter Parameter Value" window that asks me
to enter the [Course_IDFilter] value again.

What have I missed?

many thanks
sandy
 
G

Guest

Sandy,

You are mixing a string literal with the value of either a field or control
name. If the value in [Course_IDFilter] is a number, try:

Me.Filter = "[Course_ID] = " & [Course_IDFilter]

If the value is a string enclose the value in single quotes:

Me.Filter = "[Course_ID] = " & "'" & [Course_IDFilter] & "'"

Hope that helps.
Sprinks
 
G

Guest

THANK YOU!!!

Sprinks said:
Sandy,

You are mixing a string literal with the value of either a field or control
name. If the value in [Course_IDFilter] is a number, try:

Me.Filter = "[Course_ID] = " & [Course_IDFilter]

If the value is a string enclose the value in single quotes:

Me.Filter = "[Course_ID] = " & "'" & [Course_IDFilter] & "'"

Hope that helps.
Sprinks

Sandy said:
Hello -

I have the following Procedure:

Private Sub Course_IDFilter_Exit(Cancel As Integer)
Dim StringWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to
append to.


Me.Filter = "[Course_ID]=[Course_IDFilter]"
Me.FilterOn = True

End Sub

The objective is to apply a filter to the data in the detail section of a
form for all records with [Course_ID] = to the number in the unbound
[Course_IDFilter] field after a course ID is entered into it.

The filter works, but I get an "Enter Parameter Value" window that asks me
to enter the [Course_IDFilter] value again.

What have I missed?

many thanks
sandy
 

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