PDA

View Full Version : ActiveDocument.Path



jandrade15
03-19-2005, 06:58 PM
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......

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


here is the code that wont work????
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

Thanks Again!

Jacob Hilderbrand
03-19-2005, 07:06 PM
Does the Message Box display the correct path?

jandrade15
03-19-2005, 08:04 PM
Yes it does!!!