Yes John,
This string literal idea is great when one wants to insert string variables, however I am attempting to insert
strings, dates (and for a little spice) double values into a table. I am trying to run the following query using
a string variable to break things up:
msg = "INSERT INTO Valuation (PlantNum, Date, FV, IRV) "
msg = msg + "VALUES (" & stPNum + ", "
msg = msg & valDate + ", "
msg = msg & dblFV
msg = msg + ", " & dblIRV
msg = msg + ");"
DoCmd.RunSQL msg, True
valDate is a Date variable and dblFV & dblIRV are obviously double variables.
The msg constructs properly, however when one tries to run the DoCmd operation, Access returns Error 3134 -
Syntax Error. Frustrated, I re-wrote the insert query as follows (it should all be on one line, wrap before the first
ampersand on the second line):
msg = "INSERT INTO Valuation (PlantNum, Date, FV, IRV) VALUES (" & stPNum & ", " & valDate & ", "
& dblFV & ", " & ", " & dblIRV & ");"
DoCmd.RunSQL msg, True
Again this provides me with a syntax error. Any suggestions? Sorry if the answer is straightforward to the guns
on this system
Shane
----- John Viescas wrote: -----
Jennifer-
RunSQL requires a string literal or variable. Try this:
Sub append()
DoCmd.RunSQL "INSERT INTO tblMainTable " & _
"( [VALUE], [COUNT], AREA, MEAN, STD ) " & _
"SELECT maya98.VALUE, maya98.COUNT, maya98.AREA, " & _
"maya98.MEAN, maya98.STD FROM maya98;"
End Sub
--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR?pg=personal&fr_id=1090&px=1434411
Jennifer said:
Hi. sorry if this is obvious, but I'm new to VBA. I've
tried this myself, but am getting syntax errors and the
arrangement of the brackets in the SQL view is quite
different from that of the stated syntax in the RunSQL
help. Below is the code exactly as copied and pasted. I
presume I need to put brackets around the SQL statement,
but that doesn't help. Any advice?
DoCmd.RunSQL INSERT INTO tblMainTable ( [VALUE], [COUNT],
AREA, MEAN, STD )
SELECT maya98.VALUE, maya98.COUNT, maya98.AREA,
maya98.MEAN, maya98.STD
FROM maya98;
End Sub