PDA

View Full Version : Is it possible to create a mail merge of a specific table from ms access into msexcel



wedd
01-19-2011, 10:06 AM
Is it possible to create a mail merge of a specific table or form stroring data from an ms access into ms excel? if so, how can this be done?


Thanks for your contributions:friends:

CreganTur
01-19-2011, 11:25 AM
What exactly are you wanting to do with this data? If you're doing a true mail merge then yo would need Word to put the records into a document of some sort. I have code for that, but want to find out exactly what you mean.

You post a lot of questions, and that is fantastic- keep it up!, but it would be helpful if you could be more specific and provide more detail.

wedd
01-20-2011, 06:22 AM
We would like to do a mailmerge with a document in word, to write to all our hirers from time to time. Is this possible using the Access database system? I am developing a hiring out vehicle databse which records our transactions with customers so if your code could be useful for this it would be a giant step forward. Thanks!

CreganTur
01-20-2011, 07:09 AM
This code will open up a a word document that has been formatted for mail merge and link that document to your database.

strFilepath is the path to the word document you want to populate.

strQuery is the name of the query in your database that contains the records to be populated.



Sub OpenLetters(strFilePath As String, strQuery As String)

Set objWord = New Word.Application
objWord.Visible = True
Set objDoc = objWord.Documents.Open(strFilePath)
'mail merge
objDoc.MailMerge.OpenDataSource Name:="C:\Database.mdb", LinkToSource:=True, _
AddToRecentFiles:=False, Connection:="QUERY " & strQuery, _
SQLStatement:="SELECT * FROM [" & strQuery & "]"
objDoc.MailMerge.ViewMailMergeFieldCodes = False

End Sub

You'll have to setup your word document ahead of time with mergefields where you want the record values to be inserted. Make sure that the mergefieldnames exactly match the field names in your query.

HTH

wedd
01-25-2011, 05:38 AM
Thanks, Randy!