Hi,
I currently have VB code that forces a mail merge from Access to Word. I want to modify the code so that a user can browse and select the path for the Access Database (source) and the Word Template. When I have tried to make the file path for the database a variable, it has produced a run-time error. Here is my code. The bold word is my variable path name, and the path name it is (I believe) set equal to is listed below.
Dim objWord As Word.Document
Set objWord = GetObject("C:\Work\RBI Narratives\Narrative Merge Template.doc", “Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="Dim objWord As Word.Document
Set objWord = GetObject("C:\Work\RBI Narratives\Narrative Merge Template.doc", “Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:=DataBaseLocation, _
LinkToSource:=True, _
Connection:="TABLE [Narrative Data Source]", _
SQLStatement:="SELECT * FROM [Narrative Data Source]"
objWord.MailMerge.Execute
"C:\Program Files\Microsoft Office\Office11\Samples\Narrative Creator.mdb"
Can anyone see a problem with my code or see any problems with what I want to do?
Thanks
I currently have VB code that forces a mail merge from Access to Word. I want to modify the code so that a user can browse and select the path for the Access Database (source) and the Word Template. When I have tried to make the file path for the database a variable, it has produced a run-time error. Here is my code. The bold word is my variable path name, and the path name it is (I believe) set equal to is listed below.
Dim objWord As Word.Document
Set objWord = GetObject("C:\Work\RBI Narratives\Narrative Merge Template.doc", “Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="Dim objWord As Word.Document
Set objWord = GetObject("C:\Work\RBI Narratives\Narrative Merge Template.doc", “Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:=DataBaseLocation, _
LinkToSource:=True, _
Connection:="TABLE [Narrative Data Source]", _
SQLStatement:="SELECT * FROM [Narrative Data Source]"
objWord.MailMerge.Execute
"C:\Program Files\Microsoft Office\Office11\Samples\Narrative Creator.mdb"
Can anyone see a problem with my code or see any problems with what I want to do?
Thanks