Results 1 to 3 of 3

Importing Data Via Macro

Threaded View

  1. #1
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Importing Data Via Macro

    I have the following code that I cobbled together from various recordings of data imports and queries. Can someone help me with the syntax? The problem seems to be in my WHERE statment. I get a "Run-time error '1004': Data type mismatch in criteria expression."

        With ActiveSheet.QueryTables.Add(Connection:=Array( _
            "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;" _
            , "Data Source=" & ActiveWorkbook.Path & "\Vendor Log.XLS;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";" _
            , "Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";" _
            , "Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;" _
            , "Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";" _
            , "Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;" _
            , "Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;" _
            , "Jet OLEDB:SFP=False"), Destination:=Range("A4"))
            .CommandType = xlCmdSql
            .CommandText = Array( _
            "SELECT Data.`Date Call Placed`, Data.`Time Call Placed`, Data.`Call Placed By`," _
            , "Data.Priority, Data.`Application Name / Hdw Type, Model, SN#`, Data.Vendor," _
            , "Data.`Date Call Returned`, Data.`Time Call Returned`, Data.`Case#`," _
            , "Data.`Problem Description, Resolution, Comments`, Data.`Date Call Closed`," _
            , "Data.`Time Call Closed`, Data.`Date Product Down`, Data.`Time Product Down`," _
            , "Data.`Date Product Up`, Data.`Time Product Up`, Data.`Survey: Attitude`," _
            , "Data.Competence, Data.`Follow - Up`, Data.`Right Person 1st Call`," _
            , "Data.`Willing to Help`, Data.`Overall Satisfaction`, Data.`Days Open`," _
            , "Data.`Hours Down`" _
            , "FROM Data Data WHERE (Data.`Date Call Placed` Between '" & Range("B2") & "' And '" & Range("D2") & "')")
            .Name = "Vendor Log"
            .FieldNames = False
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = False
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .SourceDataFile = ActiveWorkbook.Path
            .Refresh BackgroundQuery = False
        End With
    ** Edit**
    Wow. I change the path of the source to ActiveWorkBook.Path instead of a fixed path, and it asks me to "Please enter MS Jet OLE DB Initialization Information".
    Last edited by Whizbang; 12-04-2009 at 12:44 PM.

Thread Information

Users Browsing this Thread

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

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