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

merge word docs to one print file within ADP process???

Status
Not open for further replies.

chainedtodesk

Programmer
Feb 26, 2003
112
US
i have a current process that takes data from a name and address table and with a template generates individual word docs, which get printed and mailed (works Fine). our mailroom recently upgraded to a new printer, and has requested that the word doc's anywhere from 10-2500 be bundled to one document for ease in spooling. i can not get this to work. can it be done? Thanks

Access 2003 .ADP code to follow

Private Sub GenInvites_Click()
DoCmd.SetWarnings False
'Open Word, import the text to the bookmarks and display the letter
Set objWord = New Word.Application
objWord.Visible = False 'was True
'Open Your Recordset and move to the first record
Dim Conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
Set Conn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "Select * from dbo.Invitations_ToGo"
rs.Open strSQL, Conn, adOpenKeyset, adLockOptimistic
rs.MoveFirst
'Loop through each record of the Rs, inserting each field of the record into a Bookmark in the template
Do Until rs.EOF
Set objworddoc = objWord.Documents.Add(Template:="\\vo-alb-fs01\empireQM\dm_inputs\Invite.dot", NewTemplate:=False)
With objworddoc
.Activate '<------- important
.Bookmarks("Date").Range.Text = rs!fmtDS & vbCrLf & vbCrLf
.Bookmarks("InviteInfo").Range.Text = RTrim(rs![First Name]) & " " & RTrim(rs![Last Name]) & vbCrLf & RTrim(rs![Address 1]) & " " & RTrim(rs![Address 2]) & vbCrLf & RTrim(rs!City) & ", " & RTrim(rs!State) & " " & RTrim(rs!Zipcode) & vbCrLf & vbCrLf
End With
'Save the letter to the desired folder
Dim strhdr1 As String
strhdr1 = rs![Last Name] & "_" & rs![First Name] & "_" & rs![fmtdate]
objworddoc.SaveAs Filename:="\\Mailroom\CurrentMonth\Invitation_" & strhdr1 & ".doc"
'objworddoc.PrintOut
objworddoc.close
Set objworddoc = Nothing
rs.MoveNext
Loop
objWord.Quit
Set objWord = Nothing
MsgBox "Invitation Process Is Complete, Mailroom Can Be Notified To Print", vbOKOnly
End Sub
 
How about creating the Word Document as a MailMerge with the MergeSource being a table or view in the database.

Your code would then only need to fill the table. Opening the Document and hitting Merge to file to create the big file, or Merge to Printer to print them all.
JimFive
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top