Hi All (yet ANOTHER question)
The reason for the merge is to create a Quote letter for the selected customer. It's working fine except for the contact address not showing. I have re-written the code, double checked the names and complied it. (I have attached a screen shot of the letter produced). All the other fields are merged into the letter fine but just not the 4 address lines?!! My code is as follows:
Any Ideas would be more than welcome.
Thanks
Jane
The reason for the merge is to create a Quote letter for the selected customer. It's working fine except for the contact address not showing. I have re-written the code, double checked the names and complied it. (I have attached a screen shot of the letter produced). All the other fields are merged into the letter fine but just not the 4 address lines?!! My code is as follows:
Code:
Private Sub cmd_MailMerge_Click()
On Error GoTo cmd_MailMerge_Err
Dim objWord As Word.Application
'Start Microsoft Word.
Set objWord = CreateObject("Word.Application")
With objWord
'Make the application visible.
.Visible = True
'Open the document.
.Documents.Open ("C:\Users\Jane\Documents\College - Year2\Workbased Learning\CHS_New_Quote.docx")
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("Acc_ID").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!tbl_customers_AccID))
.ActiveDocument.Bookmarks("Prop_ID").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!PropID))
.ActiveDocument.Bookmarks("Title1").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!Title1))
.ActiveDocument.Bookmarks("Firstname1").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!CustName1))
.ActiveDocument.Bookmarks("Surname1").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!CustSurname1))
.ActiveDocument.Bookmarks("Title2").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!Title2))
.ActiveDocument.Bookmarks("Firstname2").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!CustName2))
.ActiveDocument.Bookmarks("Surname2").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!CustSurname2))
.ActiveDocument.Bookmarks("ContactLn1").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!AddressLn1))
.ActiveDocument.Bookmarks("ContactLn2").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!AddressLn2))
.ActiveDocument.Bookmarks("ContactLn3").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!AddressLn3))
.ActiveDocument.Bookmarks("ContactLn4").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!AddressLn4))
.ActiveDocument.Bookmarks("ContactPostcode").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!tbl_customers_PostCode))
.ActiveDocument.Bookmarks("AddLn1").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!PAddresLn1))
.ActiveDocument.Bookmarks("AddLn2").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!PAddresLn2))
.ActiveDocument.Bookmarks("AddPostcode").Select
.Selection.Text = (CStr(Forms!frm_mailmerge!tbl_properties_PostCode))
End With
'Save the document.
Dim FName As String
FName = "Quote_" & Forms!frm_mailmerge!tbl_customers_AccID & "_" & Forms!frm_mailmerge!tbl_properties_PostCode & ".docx"
objWord.ActiveDocument.SaveAs FileName:=FName
Exit Sub
cmd_MailMerge_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
Exit Sub
End Sub
Thanks
Jane
Comment