Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quote marks in VBA 2

Status
Not open for further replies.

MikeRBS

IS-IT--Management
Apr 15, 2004
81
GB
I had a query which worked fine so I've tried to move it into a module but the IDE complains. It says something like "expected end of statement" and highights the bold bit below.

DoCmd.RunSQL "INSERT INTO Inv_StaffList ( Surname, Forename)" & _
"SELECT Mid([DEV_CONTACT],(InStr(1,[DEV_CONTACT]," ")+1),((Len([DEV_CONTACT]))-InStr(1,[DEV_CONTACT]," ")))," & _
"Left([DEV_CONTACT],(InStr(1,[DEV_CONTACT]," ")-1))," & _
"FROM Applications",-1

My guess is it is having a problem with a quote appearing within a quoted string. How do you get around that?
 
If you need a quote in a string you need to insert 2 quotes:
Code:
DoCmd.RunSQL "INSERT INTO Inv_StaffList ( Surname, Forename)" & _
"SELECT  Mid([DEV_CONTACT],(InStr(1,[DEV_CONTACT],[COLOR=red]"[/color]" "[COLOR=red]"[/color])+1),((Len([DEV_CONTACT]))-InStr(1,[DEV_CONTACT],[COLOR=red]"[/color]" "[COLOR=red]"[/color])))," & _
        "Left([DEV_CONTACT],(InStr(1,[DEV_CONTACT],[COLOR=red]"[/color]" "[COLOR=red]"[/color])-1))," & _
"FROM Applications",-1

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Ben

You're a star.

Hence the star.

Many thanks

Mike
 
Thanks for this tip! I have traditionally always used CHR$(34) to represent a double-quote. I will have to try your method!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top