I use the code below to merge the data from a form into a word document (approval.doc) when the user clicks on a command button.
Private Sub cmdMergeIt_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery “Approval”
DoCmd.SetWarnings True
Dim WordObj As Word.Document
Dim strPathtoYourDocument As String
strPathtoYourDocument = “C:Approvalsapproval.doc”
Set WordObj = GetObject(strPathtoYourDocument)
WordObj.Application.Visible = True
WordObj.MailMerge.Destination = wdSendToNewDocument
WordObj.MailMerge.Execute
WordObj.Close wdDoNotSaveChanges
Set WordObj = Nothing
End Sub
This all works great, however, I have a request to expand the functionality of the merge.
The form used in this merge also contains a Combo Box Named “Vendor” that has a drop down list of vendor names linked to a table. The request is when “XYZ vendor” is chosen in the combo box, a different approval letter is used (let’s call it approval2.doc). The data for approval2.doc comes from the same table approval.doc, its just is in a different format. So I need to incorporate some sort of if statement that says if the combo box says “XYZ Vendor” choose approval2.doc to do the merge, else, use approval.doc. In the future, there may be a need to to further associate distinct approval letters with specific vendors.
Unfortunately I have only the most rudimentary knowledge of VBA, and this is beyond my capabilities. I have searched around for some examples of VBA code that might do this, but I have not found anything I could use, or made sense to me. Any ideas as to how to get this to work would be greatly appreciated.
Thanks