PDA

View Full Version : Error when Applying a Filter



ironj32
05-12-2009, 10:16 AM
I have a user form with an Update button on it, which when clicked I want it to Filter the records to the current one. I have tried the following code (which has worked in other db's I created):

Private Sub cmdUpdate_Click()
DoCmd.ApplyFilter , "Application Name = " & Me.txtAppName
End Sub


I keep getting the following error:

Run-time error '3075':
Syntax error (missing operator) in query expression 'Application Name = Pro 1099'.

Pro 1099 being the value that is currently in the txtAppName text box. I have been trying to figure this out for a couple days now, but just can't seem to resolve it. Any suggestions would be much appreciated!

CreganTur
05-12-2009, 10:19 AM
Try this:


Private Sub cmdUpdate_Click()
DoCmd.ApplyFilter , "Application Name = '" & Me.txtAppName & "'"
End Sub


This function requires a parameter much like the WHERE condition of a SQL string- this means any values have to be declared wiht data qualifiers- for string, wrap in single quotes; for dates, wrap in pound signs (#); for numbers, no qualifier is needed.

HTH:thumb

ironj32
05-12-2009, 10:35 AM
Thanks for the suggestion! However, now get the same error but it says (items in bold are different):

Run-time error '3075':
Syntax error (missing operator) in query expression 'Application Name = 'Pro 1099"

OBP
05-13-2009, 06:23 AM
Perhaps it needs the alternate version of

DoCmd.ApplyFilter , "Application Name = """ & Me.txtAppName & """"

MS VBA Filter and SQL Syntax is an Absolute minefield. :dunno