Openform with filter

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

Guest

Problem with syntax in filter
In form1 user click a name in listbox. This name is stored in a variable.
Then I want to open another form, where the variable decides which post is
shown.

Private Sub Elever_Click(Cancel As Integer)
Dim elev As Variant
elev = Me.Felt3.Value
DoCmd.OpenForm "Form 2", acPreview, , "Felt1 = 'elev'"
End Sub

"Felt1 = 'elev'" - This is the problem!
Sorry about my english - hope to hear from you...
 
You are assigning a value to a variable, elev, but then including the name of
the variable in a literal string expression as the WhereCondition of the
OpenForm method. The code will filter the form to return records where the
value of the Felt1 field is 'elev', which will presumably be no records.
Instead, concatenate the value of the variable into the string expression:

DoCmd.OpenForm "Form 2", acPreview, , "Felt1 = """ & elev & """"

BTW your English is excellent.

Ken Sheridan
Stafford, England
 
Thank you very much. It's working. I have tried for several hours with no
solution, so I am very pleased...
 
Ken said:
You are assigning a value to a variable, elev, but then including the name of
the variable in a literal string expression as the WhereCondition of the
OpenForm method. The code will filter the form to return records where the
value of the Felt1 field is 'elev', which will presumably be no records.
Instead, concatenate the value of the variable into the string expression:

DoCmd.OpenForm "Form 2", acPreview, , "Felt1 = """ & elev & """"

BTW your English is excellent.

Ken Sheridan
Stafford, England

:
 

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

Back
Top