By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,071 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,071 IT Pros & Developers. It's quick & easy.

Merging Access data with Word

P: 25
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_MailMerge_Click()
  2.     On Error GoTo cmd_MailMerge_Err
  3.  
  4.     Dim objWord As Word.Application
  5.  
  6.    'Start Microsoft Word.
  7.     Set objWord = CreateObject("Word.Application")
  8.  
  9.     With objWord
  10.         'Make the application visible.
  11.         .Visible = True
  12.  
  13.         'Open the document.
  14.         .Documents.Open ("C:\Users\Jane\Documents\College - Year2\Workbased Learning\CHS_New_Quote.docx")
  15.  
  16.         'Move to each bookmark and insert text from the form.
  17.         .ActiveDocument.Bookmarks("Acc_ID").Select
  18.         .Selection.Text = (CStr(Forms!frm_mailmerge!tbl_customers_AccID))
  19.         .ActiveDocument.Bookmarks("Prop_ID").Select
  20.         .Selection.Text = (CStr(Forms!frm_mailmerge!PropID))
  21.         .ActiveDocument.Bookmarks("Title1").Select
  22.         .Selection.Text = (CStr(Forms!frm_mailmerge!Title1))
  23.         .ActiveDocument.Bookmarks("Firstname1").Select
  24.         .Selection.Text = (CStr(Forms!frm_mailmerge!CustName1))
  25.         .ActiveDocument.Bookmarks("Surname1").Select
  26.         .Selection.Text = (CStr(Forms!frm_mailmerge!CustSurname1))
  27.         .ActiveDocument.Bookmarks("Title2").Select
  28.         .Selection.Text = (CStr(Forms!frm_mailmerge!Title2))
  29.         .ActiveDocument.Bookmarks("Firstname2").Select
  30.         .Selection.Text = (CStr(Forms!frm_mailmerge!CustName2))
  31.         .ActiveDocument.Bookmarks("Surname2").Select
  32.         .Selection.Text = (CStr(Forms!frm_mailmerge!CustSurname2))
  33.         .ActiveDocument.Bookmarks("ContactLn1").Select
  34.         .Selection.Text = (CStr(Forms!frm_mailmerge!AddressLn1))
  35.         .ActiveDocument.Bookmarks("ContactLn2").Select
  36.         .Selection.Text = (CStr(Forms!frm_mailmerge!AddressLn2))
  37.         .ActiveDocument.Bookmarks("ContactLn3").Select
  38.         .Selection.Text = (CStr(Forms!frm_mailmerge!AddressLn3))
  39.         .ActiveDocument.Bookmarks("ContactLn4").Select
  40.         .Selection.Text = (CStr(Forms!frm_mailmerge!AddressLn4))
  41.         .ActiveDocument.Bookmarks("ContactPostcode").Select
  42.         .Selection.Text = (CStr(Forms!frm_mailmerge!tbl_customers_PostCode))
  43.         .ActiveDocument.Bookmarks("AddLn1").Select
  44.         .Selection.Text = (CStr(Forms!frm_mailmerge!PAddresLn1))
  45.         .ActiveDocument.Bookmarks("AddLn2").Select
  46.         .Selection.Text = (CStr(Forms!frm_mailmerge!PAddresLn2))
  47.         .ActiveDocument.Bookmarks("AddPostcode").Select
  48.         .Selection.Text = (CStr(Forms!frm_mailmerge!tbl_properties_PostCode))
  49.  
  50.     End With
  51.  
  52.     'Save the document.
  53.     Dim FName As String
  54.     FName = "Quote_" & Forms!frm_mailmerge!tbl_customers_AccID & "_" & Forms!frm_mailmerge!tbl_properties_PostCode & ".docx"
  55.     objWord.ActiveDocument.SaveAs FileName:=FName
  56.  
  57.     Exit Sub
  58.  
  59. cmd_MailMerge_Err:
  60.     'If a field on the form is empty, remove the bookmark text, and
  61.     'continue.
  62.     If Err.Number = 94 Then
  63.         objWord.Selection.Text = ""
  64.         Resume Next
  65.     End If
  66.  
  67.     Exit Sub
  68. End Sub
Any Ideas would be more than welcome.
Thanks
Jane
Attached Images
File Type: jpg quote error.jpg (12.7 KB, 159 views)
Apr 24 '09 #1
Share this Question
Share on Google+
2 Replies


NeoPa
Expert Mod 15k+
P: 31,709
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.
Apr 24 '09 #2

southoz
P: 24
maybe this can send you in the right direction see

http://bytes.com/topic/access/answer...-word-document
May 11 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.