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

Mail merge to MS Word from MS Access

P: 16
I have a database with a query running a make table and linked to a mail merge letter.

I have a button with the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command464_Click()
  2. Dim LWordDoc As String
  3. Dim oApp As Object
  4.  
  5. 'Path to the word document
  6. LWordDoc = "X:\AVKUK\Global Reports - DCF's etc\Customer Complaints\Letterhead DO NOT USE.doc"
  7.  
  8. If Dir(LWordDoc) = "" Then
  9. MsgBox "Document not found."
  10.  
  11. Else
  12. 'Create an instance of MS Word
  13. Set oApp = CreateObject(Class:="Word.Application")
  14. oApp.Visible = True
  15.  
  16. 'Open the Document
  17. oApp.Documents.Open FileName:=LWordDoc
  18. End If
  19.  
  20. End Sub
I want to be able to update the make table and update and open the mailmerge by pressing the button.

Where am I going wrong with my code?
Apr 21 '10 #1
Share this Question
Share on Google+
7 Replies


patjones
Expert 100+
P: 931
The code that you posted will merely open the Word document. But I don't see any code relating to a query or updating a table. Also bear in mind that you need to have the Word document properly set up to do the merge, which includes telling it where the data source for the address information is.

Pat
Apr 21 '10 #2

P: 16
What code do I need to do this? I have been searching all over the internet and have drawn a blank.

Any help at all would be appreciated.

Thank you
Apr 23 '10 #3

patjones
Expert 100+
P: 931
You need to provide more information. All you've said is that you have some table that you want to update and then merge into Word. No one can help unless you tell us more about your table, how you are trying to update it (by entering data in the form or from some other source), what fields you have, etc...

Pat
Apr 23 '10 #4

P: 16
I will try and give as much information as I think you'll need. Unfortunately like I said I am asking for help because I am new at this so please bear with me on this.

I have the following:

Query called "qryCustomerContact" with the following fields in:
CC Number (set up to look at current form record only)
Customer Name
Address1
Address2
Address3
Town
County
Postcode
Contact Name
Position
The query then goes to create a make table called "Customer Contact Make Table".

I have a word document called "Letterhead" which is set up as a mail merge looking at the make table in access.

I want to be able to press a button on my form which opens the word document and updates the fields.

I have managed to get as far as the button updating the make table and opening the word document but it doesn't update the fields.


I really hope you can help because I have drawn a blank.

Hopefully I have now provided enough information.

Thank you in advance
Apr 23 '10 #5

patjones
Expert 100+
P: 931
So, the query is correctly updating the table in Access, but you are not seeing the correct results when the Word document opens?

It sounds like you haven't set the Word document up properly. When the Word document opens there might be some other things you need to do (for instance, "Start Mail Merge" then "Select Recipients" under the Mailings tab, if you're using Word 2007).

Also, when you do a mail merge, at the point where you "Select Recipients", Word allows you to pick a query in the Access file - so you don't necessarily need to make a table in order to do this.

Pat
Apr 23 '10 #6

patjones
Expert 100+
P: 931
One other thing you can do is to paste the body of the letter into a report in Access, then add the address fields to the report to make your address block and base the report on your query. In this manner you could avoid having to do the merge with Word.

Pat
Apr 23 '10 #7

P: 16
I did try to set up straight from the query but it wouldn't let me.

The table is up to date and if I was to open the word document through explorer and not the button in access then the document updates fine.

I did consider using a report but I need to be able to amend and add text to it.
Apr 23 '10 #8

Post your reply

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