Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 13: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.RunID, 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`.RunLineDeviceRecipe 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.RunID = ProductLine.RunID AND RunLineDeviceRecipe.LineID = LineRun.LineID AND LineRun.RunID = RunLineDeviceRecipe.RunID 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.RunID" _ ) .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

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