Results 1 to 11 of 11

Importing Access table as it is.

Threaded View

  1. #1
    Registered User
    Join Date
    11-23-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    18

    Importing Access table as it is.

    i have posted previously with a similar request , and i am still trying on my own.
    i want to import one table fully from a particular MDB ( access ) file.
    i recorded a macro to that efect which looks like this.
    Sub Macro20()
    ' Macro20 Macro
    ' Macro recorded 11/23/2009 by Fpi
    
        With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
            "ODBC;DSN=MS Access Database;DBQ=D:\SSP\CURRENT NOVEMBER\R1- MDB.mdb;DefaultDir=D:\SSP\CURRENT NOVEMBER;DriverI" _
            ), Array("d=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;")), Destination _
            :=Range("A1"))
            .CommandText = Array( _
            "SELECT `Frame Section Assignments`.Story, `Frame Section Assignments`.Line, `Frame Section Assignments`.LineType, `Frame Section Assignments`.SectionType, `Frame Section Assignments`.AutoSelect, `Fram" _
            , _
            "e Section Assignments`.AnalysisSect, `Frame Section Assignments`.DesignProc, `Frame Section Assignments`.DesignSect" & Chr(13) & "" & Chr(10) & "FROM `D:\SSP\CURRENT NOVEMBER\R1- MDB`.`Frame Section Assignments` `Fram" _
            , "e Section Assignments`")
            .Name = "Query from MS Access Database_1"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .Refresh BackgroundQuery:=False
        End With
    End Sub
    Now the table extracted by this is "frame section assignments which is what i want.

    but the path of the mdb file is fixed in the above code.
    i want to make it user select or variable as per user so i modified it to the following code.

    Sub Macro200()
    Dim filename1 As Variant
    
    filename1 = Application.GetOpenFilename( _
    filefilter:="MS Access Database, *.mdb", _
    Title:="Select Your MDB file")
    
    If filename1 = False Then
    MsgBox "You Have cancelled"
    Exit Sub
    End If
    
     
        With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
            "ODBC;DSN=MS Access Database;DBQ=filename1;DefaultDir=filename1;DriverI" _
            ), Array("d=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;")), Destination _
            :=Range("A1"))
            .CommandText = Array( _
            "SELECT `Frame Section Assignments`.Story, `Frame Section Assignments`.Line, `Frame Section Assignments`.LineType, `Frame Section Assignments`.SectionType, `Frame Section Assignments`.AutoSelect, `Fram" _
            , _
            "e Section Assignments`.AnalysisSect, `Frame Section Assignments`.DesignProc, `Frame Section Assignments`.DesignSect" & Chr(13) & "" & Chr(10) & "FROM `D:\SSP\CURRENT NOVEMBER\R1- MDB`.`Frame Section Assignments` `Fram" _
            , "e Section Assignments`")
            .Name = "Query from MS Access Database_1"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .Refresh BackgroundQuery:=False
        End With
    End Sub
    but it doesnt work.. it searches for a file named "filename1.mdb"
    and it gives error.
    I Think my mistake lies somewhere in
    DSN and DBQ and Default Directory
    do guide me on this one...
    thanking you all in advance.
    --
    From,
    SSP
    Last edited by sspandit; 11-26-2009 at 01:41 AM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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