Printing single record using a command button

vangogh228

Registered User.
Local time
Today, 16:19
Joined
Apr 19, 2002
Messages
302
Hello. I am trying to write the code for a form button that will print the current record's report. I can get it to work if I use a query that asks for the issue number, but I would like to get it to do it directly from the button. The code below tries to open the report, but I really want to print from the button.

My report is called "Issues Data Report"
My form is called "Main Form"
The form field with the criterion is "Issue"


This is what I have so far:

Private Sub PrintIssueButton_Click()
On Error GoTo Err_PrintIssueButton_Click

Dim stDocName As String

stDocName = "Issues Data Report"
DoCmd.OpenReport stDocName, acNormal

Exit_PrintIssueButton_Click:
Exit Sub

Err_PrintIssueButton_Click:
MsgBox Err.Description
Resume Exit_PrintIssueButton_Click

End Sub


I appreciate your help. I know this is an easy one. I tried following the instructions from the Microsoft website 209560, but couldn't get the syntax right for some reason. I also did a search on these forums, but I am obviously missing something. THANKS!

Tom
 
Tom,

User the where clause to specify the unique record identifier. See below...


Private Sub PrintIssueButton_Click()
On Error GoTo Err_PrintIssueButton_Click

Dim stDocName As String

stDocName = "Issues Data Report"
DoCmd.OpenReport stDocName, acNormal,,"Issue = Forms![Main Form]!Issue"

Exit_PrintIssueButton_Click:
Exit Sub

Err_PrintIssueButton_Click:
MsgBox Err.Description
Resume Exit_PrintIssueButton_Click

End Sub
 
FANTASTIC! Works exactly as hoped.

I looked at the syntax of the Do statement to make sure I understood it. Thanks again!

Tom
 

Users who are viewing this thread

Back
Top Bottom