I see your point about the s. I was looking at the original post, not
the
follow up.
The parentheses are not necessary, but it still works. I tried it in
the
immediate window.
I think I found the problem and it is parentheses. This one is
unmatched:
Consignee_Name, Consignee_City, ship_ref_2)"
As to the single quotes, we will have to agree it is a matter of style.
I
find
"SELECT * FROM tblSomething WHERE SOME_FIELD = '" & Me.txtSomeValue &
"';"
much easier to read than
"SELECT * FROM tblSomething WHERE SOME_FIELD = '''" & Me.txtSomeValue &
"''';"
I have a hard time even counting how many quotes are there much less
knowing
whether 3 or 4 is the correct number to use.
:
I realize that single quotes inside double quotes are valid, but I
also
know
I have had problems getting them to work as expected. It's difficult
enough
for me to figure out three or four double quotes strung together
without
compounding the confusion by trying to add a literal quote.
As for the parentheses, s is defined as a string, but the string
starts
with
a parentheses. I would have thought that if the string is being used
for
the Execute method, the string needs to start with a quote and the
parentheses be left out. I freely admit I am unfamiliar with the
Execute
method (and could find no help whatever in Help), but a string
starting
with
a parentheses just didn't look right to me. I would have expected the
parentheses to be part of the Execute method, and the string to
replace
what
comes between the parentheses.
Perhaps if I had a clearer idea of what was being attempted I would
have
either avoided jumping in or would have provided something less
speculative.
But thanks for your observations. I am learning a bit more each day.
Using single qoutes inside double qoutes for SQL strings is
perfectly
valid.
The parentheses are for the Execute() method, also valid.
Basically, I don't see an syntax error. The parameter error in this
case
means that one of the fields identified in the VALUES list either
does
not
exist or is misspelled. I am not positive there is no syntax error,
but I
don't see it.
:
I don't think there should be a parentheses before the first double
quote
or
after the last one. If you are adding fields to the string you
need
to
insert a double quote to end the literal text before you insert the
field
name. If you are adding two fields to the string you need to
concatenate
them together:
Me.ship_num & " " & Me.ship_ref will give you the field values for
ship_num
and ship_ref with a space between them, assuming that ship_num and
ship_ref
are fields in the record source.
Which brings me to something that puzzles me: you said this code
is
part
of
a query, but the string would seem to be part of VBA code, which
means
it
is
associated with a form or report. How does the object in which the
code
appears fit into the picture? Where in the query were you trying
to
place
the code originally?
Also, there are some single quotes that I take it are supposed to
be
part
of
the string, but they could be confounding things. When I need a
literal
quote or apostrophe to appear I tend to use chr(34) and chr(39):
"#, " & chr(39) should give you a number sign, a comma, a space,
and
an
apostrophe.
Remember, that is only if you need a quote mark or apostrophe in
the
text
string, not for the quotes marks that surround literal text values.
Hi TC,
I did that.
Dim s As String
s = ("INSERT INTO BIll ([bill].[pickup_dt], Inv_num,
[bill].[Inv_dt],
ship_num, ship_ref_1, net_chg, fuel_net_chg, VAT, Consignee_Name,
Consignee_City, ship_ref_2)" _
& "VALUES( #" & pck_dt & "#, '" & Inv_num & "', #" & inv_dt & "#,
'"
&
ship_num & "', '" & ship_r_1 & "', " & nchg & ", " & nfuel & ", "
&
VAT
&
", " & con_nm & ", " & con_cty & ", '" & dept & "');")
Debug.Print s '<==
It didn't do anything... at all. What does it mean?
TIA,
Jarryd
Jarryd, it's hard to wade through actual code, when there's a
simpler
way to see what's happening. Instead of putting the SQL string
directly
into the Execute call, store it into a string variable first.
Then
you
can print it to the debug window, which usually makes it easier
to
see
what is actually being executed:
dim s as string
s = "INSERT INTO etc. etc. etc.
debug.print s ' <==
db.execute s
Then look at the outpout in the debug window.
My bet is, a string quote error
HTH,
TC [MVP Access]