Syntax error

drag1c

Board Regular
Joined
Aug 7, 2019
Messages
92
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hi,

I am trying to combine two different sources of informations to one row in SQL:
1 source) Excel table (Headers from Routing Number to Expected UoM)
2 source) VBA code : Application.Username and VBA.Now (From Account Name to Creation Date) * - this part of VBA code is not yet finished so I am using VALUES ('TEST', 02/02/2023) as random data just to have something written.
At end, 2 source) will look like (but not important for topic):
Code:
VALUES(" & Application.Username & "," & VBA.Now & ")"

Syntax part:

Code:
"INSERT INTO db_workplans ([Routing Number],[Target Date],[Material/Asset],[Description],[Type],[Consumption],[UoM],[Expected UoM],[Account Name],[Creation Date]) SELECT * FROM [Excel 12.0;HDR=YES;IMEX=1;Database=" & "C:\Users\xxxxxx\Desktop\Book1.xlsb" & "].[Sheet1$A1:H5] AND VALUES ('TEST',02/02/2023) WHERE [Material] = 'TEST'"

Error is:
Syntax error in FROM clause.

I've tested both SELECT * FROM and VALUES but separately and they work, but I don't know how to combine them into one query to update 1 row.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try
Code:
"INSERT INTO db_workplans ([Routing Number],[Target Date],[Material/Asset],[Description],[Type],[Consumption],[UoM],[Expected UoM],[Account Name],[Creation Date]) 
    SELECT * FROM [Excel 12.0;HDR=YES;IMEX=1;Database=" & "C:\Users\xxxxxx\Desktop\Book1.xlsb" & "].[Sheet1$A1:H5], 'TEST',#02/02/2023# WHERE [Material] = 'TEST'"
 
Upvote 1
Solution

Forum statistics

Threads
1,215,084
Messages
6,123,021
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top