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

batch printing: prompt user once for printer; can it be done?

Status
Not open for further replies.

misterstick

Programmer
Apr 7, 2000
633
GB
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?


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. <;)
 
all right.

the code as published works just fine in access 2000.

googling further pulled up this page, which suggests that this is a problem with 2003 sp2 and the UseDefaultPrinter property of a report.

unfortunately, as far as i can tell, the UseDefaultPrinter option is not saved in a 2000 database, since setting the property to false, saving the report, and then reading the property gives true every time.

guess i'll have to assume that all my users will either be running 2000 or have this special sp2 hotfix installed, eh? ;-)

hope this helps someone else,


mr s. <;)
 
Another idea which I have used successfully. It was originally designed to specify a particular printer for warehouse picksheets.

First when starting the Access application, I save the user's default printer.

Then I ask the user to specify a particular printer that they want to use for the picksheets from a populated list of those available only to them.

I save each of these in a table (I use a local front-end table for that but it could be adapted to use a back-end table with the user name specified).

When sending the report, I first sent a copy to the default printer, then using code changed the users default printer to the warehouse one and sent the report(s) there. Then I changed the users default printer back to their original default.

The original base source I used for the code was found on the web from the Access 95 How-To book by Ken Gatz and Paul Litwin but I had to modify it to suit exactly what I wanted.

Of course you could ask for the specified printer at any stage within the application.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top