I hope someone can help; furthermore, please be aware that my knowledge of the correct terminology may not be 100% accurate but I do hope that you will afford me some understanding because of that.
I am using Word and Access 2000.
I have created some code (linked to a command button on a form) which opens a word document (with mergefields) and then performs the intended mail merge: the code is below.
However, I am in need of some help please with enabling the merge to take place only on the open record of the form; ie, if I am looking at record 23 and I press the command button, it merges only the data from record 23.
I have searched various forums and googled for 3 whole days this week to try and find the solution/s but to no avail; in addition, I do appreciate that many members may wish to suggest the use of a report instead of mail merge; however, I most definitely want to use mail merge and not a report.
I have come across a simple solution but it keeps bringing an error message up. I've set a criteria in the query to be:
[forms]![Reservations2]![Booking Reference]
...and this successfully brings up the query (in Datasheet View) with the data from the open record in the form.
However, when I click on the command button on my form, to perform the mail merge, it brings up a prompt box asking "Enter Parameter Value" for [forms]![Reservations2]![Booking Reference].
When I click OK on that, it also says that it couldn't merge the main document with the data source as the fields were empty...even though I know the query (in Datasheet view) is showing the data I need to merge.
Finally, my module opens up and highlights some of the code in yellow, suggesting an error ? I've attached a screenprint.
Can anyone figure out what is happening or should I forget this "simple" option as a solution ?
Many thanks
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("H:\enjoy120210\CorrespondenceLetters\MailMerge\BrksDednsEM.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Reservations.
objWord.MailMerge.OpenDataSource _
Name:="H:\enjoy120210\Reservations.mdb", _
LinkToSource:=True, _
Connection:="QUERY MasterDataSource", _
SQLStatement:="SELECT * FROM [Reservations2]"
'Execute the mail merge.
objWord.MailMerge.Execute
' Close BrksDednsEM.doc
Word.Documents("BrksDednsEM.doc").Close (Word.WdSaveOptions.wdSaveChanges)
End Function
I am using Word and Access 2000.
I have created some code (linked to a command button on a form) which opens a word document (with mergefields) and then performs the intended mail merge: the code is below.
However, I am in need of some help please with enabling the merge to take place only on the open record of the form; ie, if I am looking at record 23 and I press the command button, it merges only the data from record 23.
I have searched various forums and googled for 3 whole days this week to try and find the solution/s but to no avail; in addition, I do appreciate that many members may wish to suggest the use of a report instead of mail merge; however, I most definitely want to use mail merge and not a report.
I have come across a simple solution but it keeps bringing an error message up. I've set a criteria in the query to be:
[forms]![Reservations2]![Booking Reference]
...and this successfully brings up the query (in Datasheet View) with the data from the open record in the form.
However, when I click on the command button on my form, to perform the mail merge, it brings up a prompt box asking "Enter Parameter Value" for [forms]![Reservations2]![Booking Reference].
When I click OK on that, it also says that it couldn't merge the main document with the data source as the fields were empty...even though I know the query (in Datasheet view) is showing the data I need to merge.
Finally, my module opens up and highlights some of the code in yellow, suggesting an error ? I've attached a screenprint.
Can anyone figure out what is happening or should I forget this "simple" option as a solution ?
Many thanks
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("H:\enjoy120210\CorrespondenceLetters\MailMerge\BrksDednsEM.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Reservations.
objWord.MailMerge.OpenDataSource _
Name:="H:\enjoy120210\Reservations.mdb", _
LinkToSource:=True, _
Connection:="QUERY MasterDataSource", _
SQLStatement:="SELECT * FROM [Reservations2]"
'Execute the mail merge.
objWord.MailMerge.Execute
' Close BrksDednsEM.doc
Word.Documents("BrksDednsEM.doc").Close (Word.WdSaveOptions.wdSaveChanges)
End Function