Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Mail Merge VBA Help

Status
Not open for further replies.

shuttlelaunch

Technical User
Sep 22, 2011
15
US
Hello All,

I am trying to make a command button in Access that will fill a Word Mail Merge with information from that record set. The code I have so far is:

Code:
Set objWord = GetObject("C:\My documents\Mail Merge.docx", "Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="C:\my documents\Names Database.accdb", _
LinkToSource:=True, _
Connection:="Members"
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintPreview

The code works so far, but imports all the entries in the database, not the specific recordset being viewed.

Thanks!
 
The way I do it is use a query and spit it out to an XLS file using the transfer method.

Then use the XLS file as the data source to the mailmerge.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Downloads
 
How would you use a query? Would kind of code would I have to add to the button to run a query for the specific record being viewed?
 
Where ever you had a link to your Access table, use a query. I would probably use a little code to change the SQL property. I don't do this so you would need to do some digging.

If you get an error message regarding pulling from the query, you might need the code to update the SQL property.

Duane
Hook'D on Access
MS Access MVP
 
If I am using a from the switchboard, how do you make a query for the single record being viewed? I am not using a link to an access table.
 
I have searched the web. There is nothing for how to create a mailmerge from the single record being viewed.
 
When are viewing the database through a Form, the specific record you are looking at, not the whole table.

If I wanted to print a report with just that record, I use
the code:
Code:
DoCmd.OpenReport "LETTER_COMRATS", acViewPreview, , "ID=" & Me.ID"


Is there a mail merge equivalent for just the single record being viewed, not the whole table?
 
I would use the fChangeSQL() found in the Query forum FAQs to change the SQL property of a saved query.
Code:
dim strOldSQL as String
strOldSQL = fChangeSQL("SELECT * FROM TAD_Database WHERE ID = " & Me.ID,"YourQueryName")
Then base you merge on YourQueryName.


Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top