misterstick
Programmer
if this looks like cross-posting i apologise, i realise the other post is in the wrong foum and i've asked for it to be deleted.
i'm using Access 2003 to create an Access 2000 database which will be used on both 2000 and 2003.
the database contains ten reports.
i'd like to have a "print" button on a form which prints all ten reports.
i have code to do this, but it either prompts the user for a printer for each report or not at all.
googling about i found microsoft's method to change the printer programmatically but i can't get the example to work.
the dread "This document was previously formatted " error occurs all the time.
here's my code: do any of you have any ideas?
many thanks,
mr s. <
mr s. <
i'm using Access 2003 to create an Access 2000 database which will be used on both 2000 and 2003.
the database contains ten reports.
i'd like to have a "print" button on a form which prints all ten reports.
i have code to do this, but it either prompts the user for a printer for each report or not at all.
googling about i found microsoft's method to change the printer programmatically but i can't get the example to work.
the dread "This document was previously formatted " error occurs all the time.
here's my code: do any of you have any ideas?
Code:
' in separate module
global strDevNames as string
'in first report (SectionData)
Private Sub Report_Page()
globalDevNames = Me.PrtDevNames
End Sub
'in form that does the printing (also called SectionData)
Public Sub PrintReport(reportName As String)
DoCmd.OpenReport reportName, acViewDesign
If Len(globalDevNames) > 0 Then
Reports.Item(reportName).PrtDevNames = globalDevNames
End If
'prints to default printer, no error
'DoCmd.RunCommand acCmdQuickPrint
'"previously formatted" error for all three
'DoCmd.RunCommand acCmdPrint
'DoCmd.OpenReport reportName
'DoCmd.PrintOut
DoCmd.Close acReport, reportName, acSaveNo
End Sub
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click
Const strSectionData As String = "SectionData"
Dim doc As Document
Dim counted As Integer
Dim counter As Integer
'open first reprot, prompt for printer
DoCmd.SelectObject acReport, strSectionData, True
On Error Resume Next
DoCmd.RunCommand acCmdPrint
If Err = 2501 Then
'user clicked cancel
GoTo Exit_cmdPrint_Click
ElseIf Err <> 0 Then
'some other error
GoTo Err_cmdPrint_Click
End If
DoCmd.Close acReport, strSectionData, acSaveNo
On Error GoTo Err_cmdPrint_Click
counted = CurrentDb.Containers("Reports").Documents.Count
'loop through reports
For counter = 0 To counted - 1
Dim s As String
s = CurrentDb.Containers("Reports").Documents(counter).Name
If s <> strSectionData Then
PrintReport s
End If
Next
Exit_cmdPrint_Click:
Exit Sub
Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click
End Sub
many thanks,
mr s. <
mr s. <