Apostrophe interfering with form filter

_JSincliar

Registered User.
Local time
Today, 14:11
Joined
Dec 9, 2009
Messages
16
Hi Everyone,
I have poked around this and other forums looking for a solution to this but I haven't been able to find something I can adapt to my needs.

I have a form with two combo boxes, the first limits the selection of the second. The second applies the filter to the form and is a list of names.
The problem is when I select a name has an Apostrophe in it, (eg. O'Brien). I get:
Run-time error '3075'
Syntax error (missing operator) in query expression '[USED_NAME] = 'O'Brien, John".

I have considered using Replace() to substitute the ' with another character, but I'm unsure how to procede or if it's realistic.
Most of my code I found through searches and was able to adapt to my situation and I am still a novice with VBA.

Code:
Private Sub StudNames_cbo_AfterUpdate()
Me.FilterOn = False
Me.Filter = ""
If Not IsNull(Me.StudNames_cbo) Then
Me.FilterOn = True
Me.Filter = "[USED_NAME] ='" & Me.StudNames_cbo & "'"
Me.Detail.Visible = True
Else
Me.FilterOn = False
End If
End Sub

Thanks in advance!
 
Change

Me.Filter = "[USED_NAME] ='" & Me.StudNames_cbo & "'"

To

Me.Filter = '[USED_NAME] ="' & Me.StudNames_cbo & chr(34)
 
Thank you for your response,

I replaced my line with yours but recieved,
Compile error:
Syntax Error
Am I missing a single or double quote somewhere?
 
If at first you don't succeed
Try
Me.Filter = "[USED_NAME] =" & chr(34) & Me.StudNames_cbo & chr(34)
 

Users who are viewing this thread

Back
Top Bottom