troubleshooting Question

Select Statement using a variable with apostrophe VBA Access

Avatar of nomar2
nomar2 asked on
Microsoft Access
4 Comments1 Solution739 ViewsLast Modified:
I have a select statement that checks whether an address exists in the table.
Quite a few street names have apostrophes in the name

Murphy's Court
Adam's Pond Road

Dim strCompare, strSQL As String
Dim db As Database
Dim rs As DAO.Recordset

strCompare = Me.sStreetNumber & " " & iStreetName.Column(1)

as an example.....
strCompare = 3 Adam's Pond Road (which plugs into the select statement)

Set db = CurrentDb
strSQL = "SELECT * FROM qryresidences WHERE Res = '" & strCompare & "' "

   Set rs = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
   If rs.EOF = False Then
      MsgBox "That address exists already"
   End If


I keep getting an syntax error because of the apostrophe.

Any insight or help would be greatly appreciated.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros