-
SQL Syntax Error
I'm basic level Excel VBA and generally use the macro recorder for my SQL needs. However, the below code keeps giving me an SQL syntax error. Any help is humbly appreciated.
Set SLABQueryTable = Sheets("PAN SLAB").QueryTables.Add(Connection:="ODBC;DBQ=" & SLAB_Location & ";Driver={Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS Access;", Destination:=Sheets("PAN SLAB").Range("B1"))
With SLABQueryTable
.CommandText = ("SELECT `SAP-SLAB`.`EAN/UPC`, `SAP-SLAB`.Material, `SAP-SLAB`.Pfx, `SAP-SLAB`.ProdHy, `SAP-SLAB`.`Pfx/Pur`, `SAP-SLAB`.`Catalog Number`, `SAP-SLAB`.`Catalog Description` FROM " & SLAB_DefaultDir & "\SAP-Material SLAB`.`SAP-SLAB` `SAP-SLAB` WHERE (`SAP-SLAB`.ProdHy Like 'PAN%') OR (`SAP-SLAB`.ProdHy Like 'CWCPF%') OR (`SAP-SLAB`.ProdHy Like 'FIBPF%')")
.Name = "Query from SLAB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules