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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple creating Word Documents

Status
Not open for further replies.

LDG1234

Programmer
Jun 26, 2001
120
0
0
GB
Hi guys

Hope you can help.

I need to do the following...

I have a table with a list of customers with a contact date.
There are multiple customers, many which have the same contact date.

I want to write a function that will go in and check which customers need to be contacted every morning.

I then want this to extract their contact and contract details from a table to be used on a template letter in MS Word. I know how to automate MS word and populate the details with bookmarks for one document but I would like to know how I can create multiple letters as there will be more than one customer to contact each day. I also want to avoid opening a new session of MS Word for each letter.

Hope someone out there can help me....
It will help me out considerably.

Thanks in advance for your assistance...




Lloyd Gozzett
Process Developer
 
since you want multiple documents that are the same,instead of using bookmarks, create a word mailmerge document template with the fields you want. One problem with word is it will try to open access if it can't find an existing instance running. If your project has a name specified in the "Application Title", then word will not recognize it and will open up another instance of access. Once you create the document, you can do the entire mailmerge form within access. I just created a separate module to handle the mailmerge. Here is an example from one of my applications. I select the required records into a separate table to make it easier.

Public Sub EmailFinding()
'This module is used to email the findings for the current review.
Dim objWord As Word.Application
Dim doc As Word.Document


Dim rst As New ADODB.Recordset
Dim strSQL As String
' delete existing tblMerge table
On Error Resume Next
CurrentDb.TableDefs.Delete ("tblMerge")


strSQL = "SELECT REVIEW.REVIEW_NO, REVIEW.TITLE, REVIEW.CONTRACTOR," _
& "REVIEW.INVEST1, REVIEW.INVEST2, REVIEW.INVEST_W1, REVIEW.INVEST_W2," _
& "REVIEW.ReviewedWith1, REVIEW.ReviewedWith2, REVIEW.ReviewedWith3," _
& "REVIEW.ReviewedWith4, FINDING.KEYFIELD, FINDING.FINDING_NO," _
& "FINDING.AUD_CONTR, FINDING.AUD_NONCOM, FINDING.AUD_OP_IMP," _
& "FINDING.AUD_GOVT, FINDING.AUD_REF, FINDING.FINDING, finding.discussion into tblMerge " _
& "FROM REVIEW INNER JOIN FINDING ON REVIEW.REVIEW_NO = FINDING.KEYFIELD " _
& "WHERE REVIEW.REVIEW_NO= " & "'" & Form_frmMain.REVIEW_NO & "'"
'MsgBox strSQL


rst.Open strSQL, CurrentProject.Connection, _
adOpenStatic, adLockReadOnly

Set objWord = New Word.Application
objWord.Visible = True
Set doc = objWord.Documents.Add("review.dot", , , True)

doc.MailMerge.OpenDataSource Name:= _
CurrentProject.FullName, _
linktosource:=True, _
Connection:="Table tblMerge", Sqlstatement:=strSQL

doc.MailMerge.Execute

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top