Hello All,
The following SQL string fails because astrOrdernotes(8) has a single quote in the field. Example Henry O'Smith. The data type for this field is a string but, I keep getting a syntax error starting with this field. -
strSQL = "INSERT Into tbl_shipping_label ([Our Street],[Our City],[Address Service]," & _
-
"[First Class],[Postage],[Our City2],[Permit],[Pt Name],[Pt Street],[Pt City],[Pt CC],[Pt Orderno])" & _
-
"values ('" & astrOrdernotes(1) & "','" & astrOrdernotes(2) & "','" & astrOrdernotes(3) & "'," & _
-
"'" & astrOrdernotes(4) & "','" & astrOrdernotes(5) & "','" & astrOrdernotes(6) & "','" & astrOrdernotes(7) & "'," & _
-
"'" & astrOrdernotes(8) & "','" & astrOrdernotes(9) & "','" & astrOrdernotes(10) & "','" & astrOrdernotes(11) & "'," & _
-
"'" & astrOrdernotes(12) & "');"
-
CurrentDb.Execute strSQL, dbFailOnError
-
Any suggestions would be appreciated,
Bender
3 2779
Hiya Bender. Problem is that you are using single quotes as string delimiters for the VALUES part of your string, and when a single quote is encountered within the value it ends the string too early (as in 'O'Smith').
Access will allow the use of double-quotes in the SQL string, but you cannot type these in directly without them getting really messy in appearance (from the repeats that are necessary). The example below uses an approach of substituting another uncommon character for the double quotes in building the string (an @ in this case), then replacing these with double quotes after building: - strSQL = "INSERT Into tbl_shipping_label ([Our Street],[Our City],[Address Service]," & _
-
"[First Class],[Postage],[Our City2],[Permit],[Pt Name],[Pt Street],[Pt City],[Pt CC],[Pt Orderno])" & _
-
"values (@" & astrOrdernotes(1) & "@,@" & astrOrdernotes(2) & "@,@" & astrOrdernotes(3) & "@," & _
-
"@" & astrOrdernotes(4) & "@,@" & astrOrdernotes(5) & "@,@" & astrOrdernotes(6) & "@,@" & astrOrdernotes(7) & "@," & _
-
"@" & astrOrdernotes(8) & "@,@" & astrOrdernotes(9) & "@,@" & astrOrdernotes(10) & "@,@" & astrOrdernotes(11) & "@," & _
-
"@" & astrOrdernotes(12) & "@);"
-
strSQL = Replace(strSQL, "@", Chr(34))
In testing this I substituted for the array references to make sure it worked as expected, and certainly the string built was valid.
I could not execute the statement you supplied, but I did test the approach on a simple table with string values containing single quotes and it worked as expected.
-Stewart
Thank you very much, Stewart, this problem is solved.
The most valuable information you've given was the explanation of why this problem was occurring. I modified the delimiter here and then later on in the module for the same issue. It now works flawlessly......so far.
Good day to you and again, Thank You,
Bender
NeoPa 32,557
Recognized Expert Moderator MVP
See Quotes (') and Double-Quotes (") - Where and When to use them.
My advice (normally very much in line with Stewart's but diverges somewhat here) would be to apply a quote doubler to the data. A wrapper function that replaces single-quotes (') with two single-quotes ('') : - ..."','" & DWrapper(astrOrderNotes(9)) & "','" & ...
There are other ways of handling the issue, but handling the string terminators in SQL in a non-SQL-standard way may cause problems if you ever try to move out of the Access arena.
That may be entirely trivial in your circumstances, so you judge whether this is worth worrying about or not. It certainly works in Access.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Joe |
last post by:
Hey,
I'm going to give some background on my situation in case anyone can
point out a way around my problem altogether... for the problem
itself, please skip to the bottom of the post. thanks....
|
by: |
last post by:
Can anyone point me to a good resource to show me what potential problems I'll have converting from Access 2000 to Access 2003? I understand that 2003 can read and work with the 2000 files, but that...
|
by: PAUL |
last post by:
Hello,
I have 2 tables with a relationship set up in the dataset with vb
..net. I add a new record to the parent table then edit an existing child
record to have the new parent ID. However when I...
|
by: fniles |
last post by:
I am looping thru DataReader and constructing a sql query to insert to
another database.
When the data type of the field is string I insert the field value using a
single quote.
When the value of...
|
by: Chris |
last post by:
Hello all,
Using g++ 3.3.1 on Linux ("Linux From Scratch") I have a data
structure SCSIParams_t that I wish to print out, field-by-field.
Rather than code a long line of the form
std::cout <<...
| |
by: MindBender77 |
last post by:
Hello all,
I get an error when trying to run an append query that states duplicate output to a field name. I think because I'm trying to append records to a table that is already in the use. Below...
|
by: Rick Collard |
last post by:
Using DAO 3.6 on an Access 2002 database, I'm getting unexpected
results with the FindFirst method. Here's the simple code to test:
Public Sub FindIt()
Dim db As Database, rs As Recordset...
|
by: MindBender77 |
last post by:
Hello Again All,
I have a memo field that is backslash delimited. I am attempting to break up this field into individual fields.
Ex (memo field). \John L. Doe\\StreetName RD\\City, Pa 11111
...
|
by: MindBender77 |
last post by:
Hello All,
I'm not sure if this is possible and have been unsuccessful in my attempts.
Scenerio: I have a report with several fields. If the data in field X = Y then shade the entire row.
...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |