+ Reply to Thread
Results 1 to 2 of 2

Connection String In Excel

Hybrid View

  1. #1
    Registered User
    Join Date
    04-16-2008
    Posts
    2

    Connection String In Excel

    I have an Excel workbook and Access Database that are going to be moved around a lot but always in the same directory. I have a Database Connection String in the Excel workbook as follows:

    DSN=MS Access Database;
    DBQ=C:\Databases\MCD.mdb;
    DefaultDir=C:\Databases;
    DriverId=25;
    FIL=MS Access;
    MaxBufferSize=2048;
    PageTimeout=5;

    I want to set DBQ and DefaultDir to be the current workbook path. I know I can use ThisWorkbook.Path using VBA. But, How can I accomplish this in the connection string under connection properties?

    Thanks,

    Mark Foster

  2. #2
    Forum Contributor
    Join Date
    03-24-2004
    Location
    Edam Netherlands
    Posts
    181
    I use something like this:

    Dim Connection As ADODB.Connection
    Dim sConnect as String
    
    sConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & Thisworkbook.Path & "\pbo.mdb';"
    
    Set Connection = New ADODB.Connection
    Connection.Open ConnectionString:=sConnect
    
    .................
    .................
    
    Connection.Close
    Set Connection = Nothing

+ 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