Merging Access data with Word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Newbie23
    New Member
    • Jan 2009
    • 25

    #1

    Merging Access data with Word

    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:
    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
    Any Ideas would be more than welcome.
    Thanks
    Jane
    Attached Files
    Last edited by NeoPa; Apr 24 '09, 05:04 PM. Reason: Please use the [CODE] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    Jane,

    For the question, I would suggest checking the precise names of the bookmarks for the address items that are not working.

    As for posting code, I have mentioned this before (about using [ CODE ] tags). You're getting to the level of Frequent Offender. Please remember always in future to use the tags whenever posting code. This is a requirement of the site.

    Comment

    • southoz
      New Member
      • Sep 2006
      • 24

      #3
      maybe this can send you in the right direction see

      Comment

      Working...