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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Error in INTO STATEMENT.....?????

Status
Not open for further replies.

JZII

Technical User
Jan 26, 2001
37
SE
Where is the problem.....
It´s in swedish.....
-------------------------------

Private Sub cmdCopyPost_Click()

DoCmd.RunSQL ("INSERT INTO Leverantörer-Entreprenörer ([Kategori]" _
& ", [Företag], [Adress], [Postnr/Postort], [Kontaktperson], [Telefon], [Mobil], [Fax], [E-post], [Ansvarig], [Datum], [Info]) " _
& "VALUES " _
& "('" & Me![Kategori] & "', " _
& "'" & Me![Företag] & "', " _
& "'" & Me![Adress] & "', " _
& "'" & Me![Postnr/Postort] & "', " _
& "'', " _
& "'" & Me![Telefon] & "', " _
& "'', " _
& "'" & Me![Fax] & "', " _
& "'', " _
& "'" & Me![Ansvarig] & "', " _
& "#" & Me![Datum] & "#, " _
& "'" & Me![Info] & "');")



Requery
DoCmd.GoToRecord , , acLast JZII
 
JZII,

Try removing the word INTO from your query. When you use the INTO keyword, SQL tries to create a new table using the table name specified. Since this table already exists, the INSERT will fail.

Hope this helps!

--
Ryan
 
JZII,

"INTO" does not create a new table, contrary to what the previous poster wrote.

It will be easier for you to diagnose this if you assign that sql to a string variable, do debug.print to get the result of all that into the immediate window, and paste the result of that into a new query. That way the query analyzer will show you where the error is.

When you have that, if you can't see what to fix, post back here with the error message you get (it will be more specific than the one you get in code) and the spot that's highlighted.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.


Remember to reward helpful tips with the stars they deserve.
 
The way that I have used to debug SQL statements is to copy them into the SQL view of a blank query design. When you switch to design view the fault in the statement is highlighted.
In this case I copied the text over and removed the joins, the result was a rejection of each of the unfilled fields, as indicated by & "'', " _
Removing these I found that the statement was still rejected because the number of value fields in the second half of the statement did not equal the number of target fields in the first half.
Removing the surplus target fields resulted in an accepted statement.
In order to build a SQL statement could I suggest that you test for a value before adding that target field, and if the value is null then the target is not added.
Declare 2 string variables, SqlStr1 and SqlStr2. Use SqlStr1 as the first half of the statement, SqlStr2 as the values. Set up each variable as the start of that section of the final Statement. Test each field and if a value exists then add that parameter to the SqlStr.
Close the SqlStr build by SqlStr1=SqlStr1 & SqlStr2 & ");"
Then docmd.Run SQL SqlStr1


Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top