Hi there,
I am trying to use VBA to query and as400 system using a cell as a criteria. i got the following from an FAQ here:
but i am getting a runtime error 1004 sql syntax error. on the
line.
i am so stuck!! any help would be greatly appreciated.
thanks all.
I am trying to use VBA to query and as400 system using a cell as a criteria. i got the following from an FAQ here:
Code:
Sub query()
'
' query Macro
' Macro recorded 01/04/2005 by Blount
'
'
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=Excel Files;DBQ=Data.xls;DefaultDir=I:\P&P PRO" _
), Array( _
"CEDURES\Shared reports\New Period Sales\2005\March 2005\Nottingham;DriverId=790;MaxBufferSize=2048;PageTimeout=5;" _
)), Destination:=Range("A1"))
.CommandText = Array("SELECT DATA.LHENDT, DATA.MQUSER, DATA.`00003`, DATA.ITEGNG" & Chr(13) & "" & Chr(10) & "FROM DATA DATA" & Chr(13) & "" & Chr(10) & "WHERE (DATA.LHENDT Like " & Sheets("Sheet1").Range("f1"))
.Name = "Query from Excel Files_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
but i am getting a runtime error 1004 sql syntax error. on the
Code:
.Refresh BackgroundQuery:=False
i am so stuck!! any help would be greatly appreciated.
thanks all.