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

Print a form

Status
Not open for further replies.

DebbieCoates

Programmer
Oct 2, 2007
23
0
0
GB
I am looking at a database that is in use the the company I work for.

on every from in the database is a print button, and behind it the code

On Error GoTo failure
Select Case Printer.Orientation
Case Is = vbPRORLandscape
Me.PrintForm
Printer.EndDoc
Case Is = vbPRORPortrait
Printer.Orientation = vbPRORLandscape
Me.PrintForm
Printer.Orientation = vbPRORPortrait
Printer.EndDoc
Case Else
GoTo failure
End Select
Exit Sub
failure:
MsgBox "Unable to determine printer orientation", vbCritical

I was wondering, rather than have this code on everyform, is it possible call a function or subroutine, and send the form name to that function/subroutine where it says Me.PrintForm

I tried this but get an error


Public Sub pr_Form(strFormName As String)
Dim frm As Form
Set frm = strFormName

On Error GoTo failure
Select Case Printer.Orientation
Case Is = vbPRORLandscape
frm.PrintForm
Printer.EndDoc
Case Is = vbPRORPortrait
Printer.Orientation = vbPRORLandscape
frm.PrintForm
Printer.Orientation = vbPRORPortrait
Printer.EndDoc
Case Else
GoTo failure
End Select
Exit Sub
failure:
MsgBox "Unable to determine printer orientation", vbCritical

End Sub
 

Almost there.

Try:
Code:
Public Sub pr_Form([blue]frmMyForm As Form[/blue])

On Error GoTo failure
  Select Case Printer.Orientation
    Case Is = vbPRORLandscape
      [blue]frmMyForm[/blue].PrintForm
      Printer.EndDoc
    Case Is = vbPRORPortrait
      Printer.Orientation = vbPRORLandscape
      [blue]frmMyForm[/blue].PrintForm
      Printer.Orientation = vbPRORPortrait
      Printer.EndDoc
    Case Else
      GoTo failure
  End Select
  Exit Sub
failure:
  MsgBox "Unable to determine printer orientation", vbCritical

End Sub
Andy to call simply say:
Code:
Call pr_Form(Me)


Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top