Run-Time error '1004' SQL Syntax Error

livetolearn4life

New Member
Joined
Jul 14, 2020
Messages
15
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
Hello,

i'm getting sql syntax error trying to return data from external data base. any assistance in figuring out what im doing wrong would be greatly appreciated!



With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"ODBC;DSN=WEDRPGNR1;UID=CDL;PWD=sAB2021", Destination:=Range("$A1")).QueryTable
.CommandText = Array( _
"SELECT DRAWMTWO.RECSEQ, DRAWMTWO.TOOLNO, DRAWMTWO.PARTNAME, DRAWMTWO.TOOLCPRE, DRAWMTWO.TOOLCODEB, DRAWMTWO.TOOLCPST, DRAWMTWO.TWOLOC, DRAWMTWO.SHOP, " _
, "DRAWMTWO.JOBNO, DRAWMTWO.TJOBNO, DRAWMTWO.DATEI, DRAWMTWO.BPREV, DRAWMTWO.REQUESTER, " _
, "WQMSTWOWCM.COMMENT" & Chr(13) & "" & Chr(10) & "FROM {oj S1099F6P.WEBPRDDT1.DRAWMTWO DRAWMTWO LEFT OUTER JOIN S1099F6P.WEBPRDDT1.WQMSTWOWCM WQMSTWOWCM, " _
, "ON DRAWMTWO.RECSEQ= WQMSTWOWCM.TWOINDX}" & Chr(13) & "" & Chr(10) & "WHERE,(DRAWMTWO.SHOP In (0,3,8,9)) AND (DRAWMTWO.TWOLOC<>'Closed'), " _
, "ORDER BY DRAWMTWO.DATEI DESC " _
)


.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_ExternalData_1"
.Refresh BackgroundQuery:=False
End With

1631801550427.png
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Ditch the comas after the underscores.
SQL:
"..., " _
"..."
 
Upvote 0
Solution

Forum statistics

Threads
1,215,461
Messages
6,124,954
Members
449,198
Latest member
MhammadishaqKhan

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