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!

Newbie!!! Printing multiple documents

Status
Not open for further replies.

maybe

Instructor
Jul 11, 2001
14
0
0
GB
Is there a way to print a letter with several address pulled from an access database. Something similar to mailmerge in word. I hope someone can help. Please!!!
 
Heres some code i wrote 2 years ago


Friend Sub PrintLetters(intTotalPages As Integer)
m_strCurrentProcedure = "PrintLetters"
On Error GoTo ErrorHandler
Dim cnPrintLetterAux As New ADODB.Connection
Dim strConnection As String

strConnection = "DSN=DebtManager"
'cnPrintLetterAux.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51; Data Source=" & App.Path & "\SDMLetterAux.mdb"
cnPrintLetterAux.ConnectionString = strConnection
cnPrintLetterAux.Open

Set WordPrint = New Word.Application
With WordPrint
.Documents.Add App.Path & "\PrintTemplate.dot"
With .ActiveDocument.MailMerge
.OpenDataSource Name:=App.Path & "\SDMLetterAux.mdb", LinkToSource:=True, AddToRecentFiles:=False, Connection:="TABLE LetterDetails"
.DataSource.FirstRecord = 1
.DataSource.LastRecord = intTotalPages
.Destination = wdSendToPrinter
.Execute
End With
End With

frmDebtorList.pgbProgress.Value = frmDebtorList.pgbProgress.Value + 1 'The 2 is for the fax and printer which are already complete
WordPrint.Quit wdDoNotSaveChanges
Exit Sub

ErrorHandler:
If Err.Number = 4198 Then 'cancel on the print dialog was clicked
WordPrint.Quit wdDoNotSaveChanges
MsgBox "Printing cancelled", , "Cancelled"
Else
MsgBox Err.Number & " - " & Err.Description & vbCrLf & "An error occurred in " & m_CurrentModule & "." & m_strCurrentProcedure & vbCrLf & "Please see the vendor."
End If
End Sub


Good Luck

FW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top