Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2007, 05:39 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default Printing report

Hi,

I have a problem on printing a report.
I have a from where the user can choose wich report to print (this is a list box) and some other criteria like margins and number of copies. There is also a text box, where the printer to use is inserted by a lookup in a table (because I have different printers according to the report to print).

What I would have is that by pressing an action button 'print', the selected report prints whith the criteria on this form. So it has to take the printer that is on the form, the margins, and the number of copies. I do not want the report to be shown, only the rapport printer to the selected printer.

I know some of you will tell me to change the property in the report setting to the printer I want, but if in the future the printer to print on changes, I will have to go back to every report to change this. Know I have 3 different types of reports, and the form shows all the reports of the same report type. I will only have to change the value in the table where the report types and printers to print on are stored into... This is why I want it to work this way (if possible, but I guess yes)

I have written this code, but it is not working. Can anyone help me on this?

Private Sub cmdPrinten_Click()
On Error GoTo Err_cmdPrinten_Click

Dim strRapport As String

'check if everything has been filled in correctly
If Me.lstRapporten.ListIndex = -1 Then
    MsgBox "Gelieve een rapport uit de lijst te kiezen." & vbCrLf & _
        "Veuillez choisir un rapport dans la liste.", vbExclamation, "CobelAdmin"
    Exit Sub
End If

If IsNull(Me.cboBegindatum) Or Me.cboBegindatum = "" Then
    MsgBox "Gelieve een begindatum in te vullen." & vbCrLf & vbCrLf & _
        "Veuillez entrer une date de départ.", vbExclamation, "CobelAdmin"
    Me.cboBegindatum.SetFocus
    Exit Sub
End If

If IsNull(Me.cboEinddatum) Or Me.cboEinddatum = "" Then
    MsgBox "Gelieve een einddatum in te vullen." & vbCrLf & vbCrLf & _
        "Veuillez entrer une date de fin.", vbExclamation, "CobelAdmin"
    Me.cboEinddatum.SetFocus
    Exit Sub
End If

If Me.cboEinddatum < Me.cboBegindatum Then
    MsgBox "De einddatum bevindt zich voor de begindatum." & vbCrLf & _
        "Gelieve dit te wijzigen." & vbCrLf & vbCrLf & _
        "La date de fin se situe avant la date de départ." & vbCrLf & _
        "Veuillez corriger.", vbCritical, "CobelAdmin"
    Me.cboBegindatum = ""
    Me.cboEinddatum = ""
    Me.cboBegindatum.SetFocus
    Exit Sub
End If

If IsNull(Me.txtAantalCopies) Or Me.txtAantalCopies = "" Then
    MsgBox "Gelieve het aantal exemplaren in te vullen." & vbCrLf & vbCrLf & _
        "Veuillez remplir le nombre d'exemplaires.", vbExclamation, "CobelAdmin"
    Me.txtAantalCopies.SetFocus
    Exit Sub
End If

If Me.txtAantalCopies <= 0 Then
    MsgBox "Gelieve het aantal exemplaren minimum op 1 in te stellen." & vbCrLf & vbCrLf & _
        "Veuillez regler le nombre d'exemplaires sur minimum 1.", vbExclamation, "CobelAdmin"
    Me.txtAantalCopies = 1
    Me.txtAantalCopies.SetFocus
    Exit Sub
End If

'open the report to give the criteria to the report (printer,
'margins, number of copies), but first add 'rpt' back to the name
strRapport = Me.lstRapporten
strRapport = "rpt" & strRapport
DoCmd.OpenReport strRapport, acViewPreview

'give printer
Set Reports(strRapport).Printer = Application.Printers(Me.txtPrinter)

'give margins and number of copies
With Reports(strRapport).Printer
    .TopMargin = Me.txtMargeBoven * 567
    .BottomMargin = Me.txtMargeBeneden * 567
    .LeftMargin = Me.txtMargeLinks * 567
    .RightMargin = Me.txtMargeRechts * 567
    .Copies = Nz(Me.txtAantalCopies, 1)
End With

'print the report
DoCmd.RunCommand acCmdPrint

'close the report
DoCmd.Close acReport, strRapport
DoCmd.Maximize

'empty boxes for possible next choise
Me.cboBegindatum = ""
Me.cboEinddatum = ""
Me.lstRapporten = ""

Exit_cmdPrinten_Click:
    Exit Sub

Err_cmdPrinten_Click:
    If Err.Number <> 2501 Then MsgBox Err.Description 'error no
                              'data on report
    Resume Exit_cmdPrinten_Click

End Sub


Thanks...






Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing a Report gregalb Reporting Services 0 July 23rd, 2007 05:14 PM
Printing Report rfarmer VB How-To 1 September 27th, 2006 06:39 AM
printing report Tasha Access VBA 0 August 25th, 2004 08:22 PM
Error While printing report (Crystal report) vikaspaweb Pro VB 6 0 March 8th, 2004 09:53 AM
Printing Report jmss66 VB How-To 6 February 20th, 2004 01:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.