Results 1 to 2 of 2

Access to Excel Question

Threaded View

  1. #1
    Registered User
    Join Date
    08-28-2009
    Location
    DC
    MS-Off Ver
    Excel 2003
    Posts
    3

    Access to Excel Question

    I have recorded and modified a macro to link an access database to excel. I have very little experience with VB and am having a few problems.

    1: When I use the string filenm that is pulled from the worksheet for the file path I get the following error:
    Data file: ‘C:\file.mdb’ not found. Would you like to connect to C:\file.mdb instead?
    When the file name is hard coded I do not get this error, any way to get rid of this error?

    2: How can I import only specific columns from the database table?

    3: The data files I need to work with do not have an .mdb extension (they are db1, lf1, etc). The files are opened with access and when I replace the .db1 or other extensions with .mdb excel correctly imports all data. However, when left in the original .db1 form I get a window to “Enter MS JET OLE DB Initialization Information” and I can’t get the data to import. Can anyone help with accessing a database with out an .mdb extension?

    Here is the code I'm using:
    Range("B1").Select
    filenm = ActiveCell.Value
    
    With ActiveSheet.QueryTables.Add(Connection:=Array( _
    "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0; Password=""""; User ID=Admin;" _
    , "Data Source=filenm;" _
    , "Mode=Share Deny Write;" _
    , "Extended Properties="""";" _
    , "Jet OLEDB:System database="""";" _
    , "Jet OLEDB:Registry Path="""";" _
    , "Jet OLEDB:Database Password="""";" _
    , "Jet OLEDB:Engine Type=5;" _
    , "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 = xlCmdTable
    .CommandText = Array("BDBusVoltage")
    .Name = "LL_M1_DCH_B1P_1"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = True
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .SourceDataFile = filenm
    .Refresh BackgroundQuery:=False
    End With
    Thanks for any help.
    Last edited by Leith Ross; 08-28-2009 at 11:53 AM. Reason: Added Code Tags

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