Refresh Debug Error

mb1976

New Member
Joined
Feb 21, 2012
Messages
3
Hi,

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
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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