Import Excel Data to SQL Server

R

ryu

Not sure if I am posting in the right forum but I really need help.

I am trying to import data from Excel to an Access database using SQ
functions. I keep getting the "FROM clause syntax error". I matched m
output with the requirement on MS website and am pretty sure I have th
syntax right. Can someone help? Thanks.

Here is my code.

strSQL = "SELECT * INTO [" & sheetName & "] FROM " & _
"OPENROWSET('Microsoft.Jet.OLEDB.4.0', " & _
"'Excel 8.0;Database=C:\clients\CTim\test2.xls;', " & _
"'SELECT * FROM [" & sheetName & "$]')"
Debug.Print strSQL
cn.Execute strSQL, lngRecsAff, adExecuteNoRecord
 
J

Joel

There is a single quote in the wrong place. I also think (not sure) you need
each SELECT on its own line. Adding the vbCRLF should accomplish this. If
it doesn't work try eliminating one of the SELECT statements and see if it
works.

strSQL = "SELECT * INTO [" & sheetName & "] FROM " & _
"OPENROWSET('Microsoft.Jet.OLEDB.4.0', " & _
"'Excel 8.0;Database=C:\clients\CTim\test2.xls;', " & vbcrlf & _
"SELECT * FROM '[" & sheetName & "$]')"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top