using applyFilter with a variable

J

Jo-Anne

I am trying to apply a filter to a form based on a parameter passed through
the openArgs function. The issue arises when I use the applyFilter function.

Here is the code:

If Not IsNull(Me.OpenArgs) Then
Dim memberID As String
memberID = Me.OpenArgs
DoCmd.ApplyFilter , "memID = memberID"
End If

The problem lies in the memberID variable. If I enter a memberID value the
filter works properly. I'm sure it is a simple problem with quotes or
something having to do with recognizing variables.

Any help would be great.
 
J

Jo-Anne

Thanks for your help. Works great now!

Klatuu said:
memberID being a variable needs to be outside any quotes. Enclosed in
quotes, it is seen as a literal string.

If memberID is a string:
DoCmd.ApplyFilter , "memID = '" & memberID & "'"

If memberID is a number:
DoCmd.ApplyFilter , "memID = " & memberID
 

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