If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Problem to make query in Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-03-08, 12:32
Ashk49 Ashk49 is offline
Registered User
 
Join Date: Jun 2008
Posts: 1
Problem to make query in Excel


Hi guys, please help me with this issue.
I have a Database in access and try to make report on Excel.
I need to make a query first (several links between tables).
When I try to run it Error will appear."run_time Error '1004' Application_Defined or Object_defined Error",and highlight the ".Refresh BackgroundQueryTables:=False ".
Here is my code .
Code:
Sub Macro1()
   Sheets("DATA1").Select
   Sheets("DATA2").Range("a2:j65336").Clear
    With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
        "ODBC;DSN=MS Access Database;DBQ=C:\Program Files\StatPakPC\Database\test_80_2nd.mdb;DefaultDir=C:\Program Files\StatPakPC\Database;D" _
        ), Array("riverId=25;FIL=MS Access;MaxBufferSize=4096;PageTimeout=100;")), _
        Destination:=Range("A1"))

        .CommandText = Array( _
        "SELECT ProductLine.LineID, LineRun****nID, Product.ProductID, Material.MaterialName, ProductLine.UnitsPerMin, RunLineDeviceRecipe.UnitWt_SET, LineRun.ActualUnits, LineRun.ActualWt, LineRun.DateOpened, LineRun.DateClosed," _
        , _
        "ProductLine.ProductID, LineDeviceStateLog.DTReasonID, Material.MaterialID" & Chr(13) & "" & Chr(10) & "FROM  `C:\Program Files\StatPakPC\Database\test_80_2nd`.Product Product, `C:\Program Files\StatPakPC\Database\test_80_2nd`.Material Materia" _
        , _
        "l, `C:\Program Files\StatPakPC\Database\test_80_2nd`.LineRun LineRun, `C:\Program Files\StatPakPC\Database\test_80_2nd`.ProductLine ProductLine, `C:\Program Files\StatPakPC\Database\test_80_2nd`****nLineDeviceRecipe Run" _
        , _
        "LineDeviceRecipe, `C:\Program Files\StatPakPC\Database\test_80_2nd`.LineDeviceStateLog LineDeviceStateLog" & Chr(13) & "" & Chr(10) & "WHERE Material.MaterialID = Product.MaterialID AND Product.ProductID = ProductLine.ProductID AND RunLineDev" _
        , _
        "iceRecipe****nID = ProductLine****nID AND RunLineDeviceRecipe.LineID = LineRun.LineID AND LineRun****nID = RunLineDeviceRecipe****nID AND LineDeviceStateLog.LineID = LineRun.LineID AND LineDeviceStateLog.DateOpened = LineR" _
        , _
        "un.DateOpened AND LineDeviceStateLog.DateClosed = LineRun.DateClosed" & Chr(13) & "" & Chr(10) & "ORDER BY ProductLine.LineID, Material.MaterialID, LineRun****nID" _
        )
        .Name = "test_80_2nd Customer"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceConnectionFile = _
        "C:\Documents and Settings\Administrator\Application Data\Microsoft\Queries\test_80_2nd Customer.dqy"
     '   Selection.QueryTables.Refresh BackgroundQuery:=False
     '
        .Refresh BackgroundQueryTables:=False
    End With
    Sheets("ATL").Select
End Sub
Please let me know what is wrong with this code.
Thanks
Ashkan.G
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On