MS Access VBa Syntax error for filtering

I have copied the following VBA code to filter an Access list.  I am getting a syntax error for the

Private Sub Combo273_Change()

  ' If the combo box is cleared, clear the form filter.
  If Nz(Me.Combo273.Text) = "" Then
    Me.Form.Filter = ""
    Me.FilterOn = False
    
  ' If a combo box item is selected, filter for an exact match.
  ' Use the ListIndex property to check if the value is an item in the list.
  ElseIf Me.Combo273.ListIndex <> -1 Then
    Me.Form.Filter = "[Company] = '" & _
                     Replace(Me.Combo273.Text, "'", """) & "'"
    Me.FilterOn = True
    
  ' If a partial value is typed, filter for a partial company name match.
  Else
    Me.Form.Filter = "[Company] Like '*" & _
                     Replace(Me.Combo273.Text, "'", """) & "*'”
    Me.FilterOn = True

  End If
  
  ' Move the cursor to the end of the combo box.
  Me.Combo273.SetFocus
  Me.Combo273.SelStart = Len(Me.Combo273.Text)
End Sub

Open in new window


I get a Compile  and Syntax error for the following:

Me.Form.Filter = "[Company] = '" & _
                     Replace(Me.Combo273.Text, "'", """) & "'"

Thanks

Glen
GPSPOWAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
This should do:

Me.Filter = "[Company] = '" & _
                      Replace(Me!Combo273.Text, "'", """) & "'"

or:

Me.Filter = "[Company] = '" & _
                      Replace(Me!Combo273.Text, "'", "''") & "'"

/gustav
0
GPSPOWAuthor Commented:
Gustav,

I do not see the difference between the two statements.

I tried both and they are still giving me an error.

Glen
0
Rey Obrero (Capricorn1)Commented:
try this

    Me.Form.Filter = "[Company] =" & chr(34) & Me.Combo273 & chr(34)
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Gustav BrockCIOCommented:
Look again - or copy-paste - it's the quotes.

or use a variable so you can debug:

    Dim CompanyName As String
    CompanyName = Replace(Me!Combo273.Text, "'", "''")
    Me.Filter = "[Company] = '" & CompanyName & "'"

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GPSPOWAuthor Commented:
I copied the statement and it worked.

Thanks

Glen
0
Gustav BrockCIOCommented:
You are welcome!

/gustav
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.