Print based on control

A

Andrea Barton

I have a form with a print button that prints a report for the data in that
particular record. When the button is clicked, a prompt appears asking
“Print Comment?â€. If the control is checked (true) then I would like it to
print the data in the comment field along with the data for that particular
record. If the control is false I don’t want the comment data printed, only
the data for that record. I have the code set for the report on open to show
the prompt (dialog box) and the code set for the prompt (dialog box) print
comment, but it’s not working correctly, actually not at all. Any help you
can give would be greatly appreciated. Thank you.

Dialog Box
Private Sub OK_Click()
Dim strMsg As String
Dim strDocName As String
strDocName = "rptEqualizationLetter"
If Me.PrintAttach = True Then DoCmd.OpenReport strDocName,
acViewPreview, , , acDialog
Exit_OK_Click:
Exit Sub
End Sub

Report (OnOpen)
Private Sub Report_Open(Cancel As Integer)
Dim strDocName As String
strDocName = "PrintApplicationDialog"
blnOpening = True
DoCmd.OpenForm strDocName, , , , , acDialog
If IsLoaded(strDocName) = False Then Cancel = True
blnOpening = False
End Sub
 
S

Scott Lichtenberg

Andrea,

I'm not sure whether I'm understanding what you are looking to do, so this
might not be what you are looking for. It sounds like you are trying to
pass a variable into a report so you can hide/show a field on the report.
If so, the best way to do this is with the OpenArgs property.

If your comment field already exists on your form or in your record when the
user clicks the command button, you can throw up a message box to ask
whether the user want to print the comment. Use the vbYesNo option in your
message box. This will return the vbYes or vbNo value.

Dim intRV as Integer
intRV = MsgBox("Do you want to print the comment?", vbYesNo +
vbQuestion, "My Report Name")
DoCmd.OpenReport "MyReport", acViewPreview, , , acDialog, intRV

You can put a filter or where condition in the OpenReport command if
necessary.

In the OnPrint event of the detail section of your report (or whatever
section your comment field is in) add code to show or hide the comment based
on the passed in OpenArgs value

If Me.OpenArgs = vbYes 'intRV was passed in. It will be
either vbYes or vbNo
Me!Comment.Visible = True
Else
Me!Comment.Visible = False
End If


Hope this helps.
 
K

Ken Snell \(MVP\)

Note that OpenArgs property for OpenReport is available only in ACCESS 2002
and higher versions.
 
A

Andrea Barton

That worked perfectly. Thank you so much for your help and have a wonderful
week!

Andrea
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top