+ Reply to Thread
Results 1 to 2 of 2

Access to Excel Question

Hybrid 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

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Access to Excel Question

    Hello glickz,

    Welocme to the Forum!

    To make your posts easier to read, copy, and edit please wrap your code. I did it for you this time. Here is how you can do it next time.

    How to wrap your Code
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    OR you can also do this Manually by placing the tags
    [code] at the start of the first line,
    [/code] at the end of the last line.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

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