Hi,
I'm currently running this query code in an excel worksheet that is stored in the same folder as a DBF file.
I've copied this code from another worksheet (where it works fine) but am now getting a "Run time Error 1004 SQL Syntax Error" and the Refresh line is highlighted on the debugger.
Any help would be appreciated
I'm currently running this query code in an excel worksheet that is stored in the same folder as a DBF file.
Code:
Sub DataQuery()
Dim Mailbox As String
Dim sConn As String
Dim sSql As String
Dim oQt As QueryTable
Dim create As Boolean
create = True
Mailbox = ActiveWorkbook.Path
If create Then
' Result Data
sConn = "ODBC;CollatingSequence=ASCII;DBQ=C:\TEMP;DefaultDir=C:\TEMP;Deleted=1;Driver={Microsoft dBase Driver (*.dbf)};DriverId=533;FIL=dBase;"
sSql = "SELECT DESC, RETAIL FROM " & Mailbox & "\ALLOW.DBF ALLOW WHERE(ALLOW.DESC='PIPECLEANING')"
Set oQt = ActiveSheet.QueryTables.Add( _
Connection:=sConn, _
Destination:=Range("A1"), _
Sql:=sSql)
oQt.AdjustColumnWidth = False
oQt.PreserveFormatting = False
[COLOR="Red"]oQt.Refresh[/COLOR]
End If
End Sub
I've copied this code from another worksheet (where it works fine) but am now getting a "Run time Error 1004 SQL Syntax Error" and the Refresh line is highlighted on the debugger.
Any help would be appreciated