Consulting

Results 1 to 3 of 3

Thread: ActiveDocument.Path

  1. #1

    ActiveDocument.Path

    Hello all-

    I have a macro that does a mail merge. The macro has been hardcoded to where the db is located on my pc.....c:programfiles\etc....I want to make it to where the macro finds the db in the app path (VB)..... I have this code but it will not automatically find the db and the table I need?? can someone help me out please!!! Thanks so much for your time!

    here is the original code thats hardcoded but works the way I want it to......

    [VBA]Private Sub Document_Open()
    CommandBars("Mail Merge").Visible = True
    ActiveDocument.MailMerge.OpenDataSource Name:= _
    "C:\Program Files\Tracking Data\Tracking Data.mdb", ConfirmConversions:= _
    False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
    PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
    WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
    Connection:= _
    "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data _
    Source=C:\Program Files\Tracking Data\Tracking _
    Data.mdb;Mode=Read;Extended Properties="""";Jet OLEDB:System _
    database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database _
    Password="""";Jet OLEDB:Engin" _
    , SQLStatement:="SELECT * FROM `FarmingTemp`", SQLStatement1:="", _
    SubType _
    :=wdMergeSubTypeAccess
    ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
    End Sub
    [/VBA]

    here is the code that wont work????
    [VBA]private Sub Document_Open()
    Dim sPath As String
    CommandBars("Mail Merge").Visible = True
    sPath = ActiveDocument.Path & "\Tracking Data.mdb"
    MsgBox sPath
    ActiveDocument.MailMerge.OpenDataSource Name:=sPath, _
    ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
    AddToRecentFiles:=False, Revert:=False, Format:=wdOpenFormatAuto, _
    Connection:="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin; _
    Password='';Data Source=" & sPath & _
    ";Mode=Read;", SQLStatement:="SELECT * FROM 'FarmingTemp'", _
    SQLStatement1:="", SubType:=wdMergeSubTypeAccess
    ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
    End Sub[/VBA]

    Thanks Again!

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Does the Message Box display the correct path?

  3. #3
    Yes it does!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •