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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Ditch the comas after the underscores.
SQL:
"..., " _
"..."
 
Upvote 0
Solution

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

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