print command button

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

I am trying to place a "print report" button on my forms
so that I can print one record at a time easily (I have
about 1200 entries). Whenever I click on the button, it
tells me "invalid outside procedure." I'm using the
wizard to design the button; what can I do to fix the
problem manually?

Below is the code I copied off of the build event
function behind the button.

Help!

Thanks,

-ME



Me.Refresh
DoCmd.OpenReport "Potential Donors", acViewPreview, , "id
= " & Me.id
Private Sub Call_Sheet_Button_Click()
On Error GoTo Err_Call_Sheet_Button_Click

Dim stDocName As String

stDocName = "Potential Donors"
DoCmd.OpenReport stDocName, acNormal

Exit_Call_Sheet_Button_Click:
Exit Sub

Err_Call_Sheet_Button_Click:
MsgBox Err.Description
Resume Exit_Call_Sheet_Button_Click

End Sub
Private Sub Command72_Click()
On Error GoTo Err_Command72_Click

Dim stDocName As String

stDocName = "Potential Donors"
DoCmd.OpenReport stDocName, acNormal

Exit_Command72_Click:
Exit Sub
 
Matt,
According to your samples below, you have 2 different command buttons
whose click events open the same report "Potential Donors".

*** And you have code hanging all by itself (which is causing the error).
***
Me.Refresh
DoCmd.OpenReport "Potential Donors", acViewPreview, , "id = " & Me.id

is not part of any Sub Procedure.

Take either command button (I'll use the "Command72" button)
and just change the code to one of these.
1) To print ALL the records without Preview:

Private Sub Command72_Click()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "Potential Donors"
End Sub
===

2) To Print just the current Record shown on the form, without Preview:*

Private Sub Command72_Click()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "Potential Donors", , , "id = " & Me.id
End Sub
===
You can add the error handling if you wish.

Delete the unused command button AND it's code.
Also delete the
Me.Refresh
DoCmd.OpenReport "Potential Donors", acViewPreview, , "id = " & Me.id
that appears ABOVE the first Private Sub Call_Sheet code.
That's causing the error.

* If you wish to preview the report first,
change acViewNormal to acViewPreview.

acViewNormal is the default, so unless you wish something else, it need not
be explicitly entered.
However, if you are using the Filter or Where arguments you must use a comma
to mark it's place.

See VBA Help regarding all the arguments for the OpenReport method.
 
Back
Top