473,766 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Merging Access data with Word

25 New Member
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, 215 views)
Apr 24 '09 #1
2 2042
NeoPa
32,572 Recognized Expert Moderator MVP
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
24 New Member
maybe this can send you in the right direction see

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

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

Similar topics

1
2070
by: Dan Nash | last post by:
Hi guys I wonder if you could help. I'm trying to create a bespoke interface for mail merging from an Access database in Word. At the moment, I'm just trying it with CSV files, and it works. Word loads, data gets pasted in and it merges fine. One problem tho, it's doing Form Letters rather than Mailing Labels Here's the code...
5
4042
by: Jerry Hull | last post by:
I'm working with a database developed by an untrained person over several years - and on a network that has recently been upgraded with a new server installed and MS office upgraded from 2K (I think - it might have been XP) to 2003. The database is impressive, both in what it does and the obtuse and inconsistent ways it works. There are several hundred queries, for example, with no indication of where they are used or if they are in fact...
1
4959
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word 1. Query..I want to keep the fields seperatred. I do not want to sent on field with all accumulated languages from one person to Word. Each language should appear in the document in a separate cell Cross tables are not delivering the result I...
1
1693
by: jason301 | last post by:
I have started to get a problem when mail merging from my access database to word. When I mail merge the database password is requested to proceed which is odd as the database is already open. If I enter the password then the mail merge will fail. However if I click cancel when asked for the password the mail merge will work but then the database will close. I am continually working on this database and changing things which must mean...
1
4751
by: Paul H | last post by:
I have a very simple database containing one table called "tblProducts". The fields are: ProductID, Description, Price. I have a folder on my PC that contains image files. The image file names are based on the associated ProductID, i.e. 2001.jpg is a picture of ProductID 2001. I know how automate Word mailmerge using VBA in access, but I want to include the related pictures in the merged document. So the word doc will have a table in...
31
2183
by: louishong | last post by:
3rd time posting this as the first two simply disappeared! Here's the issue: We currently run an Access application in the West Coast for tracking resource centric data. For those located in the West the program zips along fine but the folks in the East Coast are having a nightmarish performance issue. We've had our tech guys take a look and it's due to the network speed across a long distance and there's nothing much that can be done.
8
6725
by: babyangel43 | last post by:
Hello, I have a query set up in Access. I run it monthly, changing "date of test". I would like this query to be merged with a Word document so that the cover letter is created in Word, the fields from Access are automatically filled into the Word document. The query could be anywhere from 0-5000 names, one cover letter per name. AND to this cover letter for each applicant, there has to be attached a two page document. How in the world can...
0
1193
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm trying to do mail merging in C#.NET and in one methods: Word.Application wrdApp; Word._Document wrdDoc; Object oMissing = System.Reflection.Missing.Value; Object oFalse = false; private void FillRow(Word._Document oDoc, int Row, string Text1,
7
4166
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm trying to follow a mail merging example in C#.Net that I got from: http://support.microsoft.com/default.aspx/kb/301659 and in one the methods: Word.Application wrdApp; Word._Document wrdDoc; Object oMissing = System.Reflection.Missing.Value; Object oFalse = false;
7
1891
by: phillyon | last post by:
I'm looking to print off a booking form based on the data in 3 linked tables by merging it in Word. Please if you know of a better way, let me know. Bookings table contains summary, cost, breakdown of cost, booking id, client id Clients table contains clientid, name, address, phone Sessions table contains date, time, activity, booking id So one client books many sessions through one booking. I can make a query that can be easily...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.