+ Reply to Thread
Results 1 to 1 of 1

Multiple Queries - Getting error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-04-2014
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    148

    Multiple Queries - Getting error

    I recorded the following macro to pull an excel tables as a query on multiple tabs. I get errors randomly from week to week on some of these sections. Thanks so much in advance!...

    .ListObject.DisplayName = "Table_Query_from_Excel_Files"

    ------------------------------------------------------------------
    THE ERROR IS 1004 GENERAL ODBC ERROR
    ------------------------------------------------------------------


    I have about 8 of them and about 4 give me the error.

    Sub ODBC_ANDOVER()
    Sheets("ANDOVER").Select
    
        With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
            "ODBC;DSN=Excel Files;DBQ=P:\_ChemUpload\Forcasts\Individual\ANDOVER.xls;DefaultDir=P:\_ChemUpload\Forcasts\Individual;DriverId" _
            ), Array("=1046;MaxBufferSize=2048;PageTimeout=5;")), Destination:=Range( _
            "$A$1")).QueryTable
            .CommandText = Array( _
            "SELECT `Sheet1$`.`Deliv# Date`, `Sheet1$`.`Deliv# Time`, `Sheet1$`.Z1, `Sheet1$`.Product, `Sheet1$`.`Ch/ Nw`, `Sheet1$`.`Order Doc# No#`, `Sheet1$`.`Item No#`, `Sheet1$`.`SL No#`, `Sheet1$`.`Prod#Desc" _
            , _
            "#`, `Sheet1$`.`Unit of Measure`, `Sheet1$`.`Document Qty#`, `Sheet1$`.`Notified Qty#`, `Sheet1$`.`Delivered Qty#`, `Sheet1$`.`Due Qty#`, `Sheet1$`.`Plant Desc#`, `Sheet1$`.`P&G MRP Controller`, `Sheet" _
            , _
            "1$`.`Last Updated`, `Sheet1$`.`Ship-From Loc#`, `Sheet1$`.`Customer Loc#`" & Chr(13) & "" & Chr(10) & "FROM `P:\_ChemUpload\Forcasts\Individual\ANDOVER.xls`.`Sheet1$` `Sheet1$`" _
            )
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .ListObject.DisplayName = "Table_Query_from_Excel_Files"
            .Refresh BackgroundQuery:=False
        End With
    End Sub
    Sub ODBC_BLOIS()
    Sheets("BLOIS").Select
    
        With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
            "ODBC;DSN=Excel Files;DBQ=P:\_ChemUpload\Forcasts\Individual\BLOIS.xls;DefaultDir=P:\_ChemUpload\Forcasts\Individual;DriverId" _
            ), Array("=1046;MaxBufferSize=2048;PageTimeout=5;")), Destination:=Range( _
            "$A$1")).QueryTable
            .CommandText = Array( _
            "SELECT `Sheet1$`.`Deliv# Date`, `Sheet1$`.`Deliv# Time`, `Sheet1$`.Z1, `Sheet1$`.Product, `Sheet1$`.`Ch/ Nw`, `Sheet1$`.`Order Doc# No#`, `Sheet1$`.`Item No#`, `Sheet1$`.`SL No#`, `Sheet1$`.`Prod#Desc" _
            , _
            "#`, `Sheet1$`.`Unit of Measure`, `Sheet1$`.`Document Qty#`, `Sheet1$`.`Notified Qty#`, `Sheet1$`.`Delivered Qty#`, `Sheet1$`.`Due Qty#`, `Sheet1$`.`Plant Desc#`, `Sheet1$`.`P&G MRP Controller`, `Sheet" _
            , _
            "1$`.`Last Updated`, `Sheet1$`.`Ship-From Loc#`, `Sheet1$`.`Customer Loc#`" & Chr(13) & "" & Chr(10) & "FROM `P:\_ChemUpload\Forcasts\Individual\BLOIS.xls`.`Sheet1$` `Sheet1$`" _
            )
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .ListObject.DisplayName = "Table_Query_from_Excel_Files1"
            .Refresh BackgroundQuery:=False
        End With
    End Sub
    Sub ODBC_CAYEY()
    Sheets("CAYEY").Select
    
        With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
            "ODBC;DSN=Excel Files;DBQ=P:\_ChemUpload\Forcasts\Individual\CAYEY.xls;DefaultDir=P:\_Upload\Forcasts\Individual;DriverId" _
            ), Array("=1046;MaxBufferSize=2048;PageTimeout=5;")), Destination:=Range( _
            "$A$1")).QueryTable
            .CommandText = Array( _
            "SELECT `Sheet1$`.`Deliv# Date`, `Sheet1$`.`Deliv# Time`, `Sheet1$`.Z1, `Sheet1$`.Product, `Sheet1$`.`Ch/ Nw`, `Sheet1$`.`Order Doc# No#`, `Sheet1$`.`Item No#`, `Sheet1$`.`SL No#`, `Sheet1$`.`Prod#Desc" _
            , _
            "#`, `Sheet1$`.`Unit of Measure`, `Sheet1$`.`Document Qty#`, `Sheet1$`.`Notified Qty#`, `Sheet1$`.`Delivered Qty#`, `Sheet1$`.`Due Qty#`, `Sheet1$`.`Plant Desc#`, `Sheet1$`.`P&G MRP Controller`, `Sheet" _
            , _
            "1$`.`Last Updated`, `Sheet1$`.`Ship-From Loc#`, `Sheet1$`.`Customer Loc#`" & Chr(13) & "" & Chr(10) & "FROM `P:\_ChemUpload\Forcasts\Individual\CAYEY.xls`.`Sheet1$` `Sheet1$`" _
            )
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .ListObject.DisplayName = "Table_Query_from_Excel_Files2"
            .Refresh BackgroundQuery:=False
        End With
    End Sub
    Last edited by hftechno; 02-24-2015 at 06:57 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Error Message - Macro to Unlink MS Queries from Workbook
    By awalker2009 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-18-2014, 07:13 AM
  2. Replies: 0
    Last Post: 01-21-2013, 12:47 PM
  3. Embedded Access queries in Excel - if the database moves, how to update queries?
    By Paul_mcc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-06-2012, 07:52 PM
  4. Multiple web queries
    By skazis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-29-2011, 07:11 AM
  5. Multiple MIN queries
    By SAsplin in forum Excel General
    Replies: 1
    Last Post: 05-09-2011, 05:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1