Inserting text containing a vertical bar by code

  • Thread starter Thread starter Per Larsen
  • Start date Start date
P

Per Larsen

Does anybody know how to insert a text containing a vertical bar (|)
into a text column by code?

I'm inserting rows to a table by code using CurrentDb.Execute strSQL,
and everything runs fine until the SQL string contains a vertical bar
like the following:

INSERT INTO bookmarks (URL, WebName) VALUES
('http://www.urbanvoyeur.com/', 'urban | voyeur')

which returns Err.Number 3075: "Syntax error in string in query
expression ''urban | voyeur''."

It's no problem inserting the same text right into the table field when
opening the table as a datasheet.

PerL
 
I was able to do the following without error (Access XP):

strSQL = "INSERT INTO bookmarks (URL, WebName) VALUES
('http://www.urbanvoyeur.com/', 'urban | voyeur')"
CurrentDb.Execute strSQL

The only way I was able to replicate your error is if I wrapped the WebName
with consecutive apostrophes:

strSQL = "INSERT INTO bookmarks (URL, WebName) VALUES
('http://www.urbanvoyeur.com/', ''urban | voyeur'')"
CurrentDb.Execute strSQL

Perhaps your strSQL isn't really getting constructed exactly as you think it
is?
 
I was able to do the following without error (Access XP):

strSQL = "INSERT INTO bookmarks (URL, WebName) VALUES
('http://www.urbanvoyeur.com/', 'urban | voyeur')"
CurrentDb.Execute strSQL

The only way I was able to replicate your error is if I wrapped the WebName
with consecutive apostrophes:

strSQL = "INSERT INTO bookmarks (URL, WebName) VALUES
('http://www.urbanvoyeur.com/', ''urban | voyeur'')"
CurrentDb.Execute strSQL

Perhaps your strSQL isn't really getting constructed exactly as you think it
is?

I'm afraid that doesn't help me in Access 97 (which I forgot to tell I'm
using). Thanks for your suggestion, anyway.

PerL
 
Back
Top