I recently emailed the below information to a friend of mine that no NOTHING hardly about Access. I know it may be trivial (or 101) to you, but I did'nt have time to edit.
This Goes in the On Click Event of your Print Button (Make sure you put the name of your Report in the NAME line at the top of the properties box of the print button).
Private Sub Incident_Click()
DoCmd.RunCommand acCmdSaveRecord
On Error GoTo Err_Incident_Click
Dim strDocName As String
strDocName = "Incident"
' Print Incident report, using Filter Incident query to print
' report for current incident.
DoCmd.OpenReport strDocName, acViewNormal, "Filter Incident"
Exit_Incident_Click:
Exit Sub
Err_Incident_Click:
' If action was cancelled by the user, don't display an error message.
Const conErrDoCmdCancelled = 2501
If (Err = conErrDoCmdCancelled) Then
Resume Exit_Incident_Click
Else
MsgBox Err.Description
Resume Exit_Incident_Click
End If
End Sub
This goes in the Criteria Line of a NEW Query you need to design.
[Forms]![frmincident]![Report ID#]
Just Open a NEW Query in Design View. Add your TABLE. Drag and drop the Asterisk at the top to the top Field Line below it. Then drag and drop the ID# in the next field line.
Add the above code in the Criteria line below the ID# field.
Be sure and change “frmincident” to the name of your form.
Below is what I typed in the initial email I tried to send you.
Good luck. Call me if you need any help.
The easiest way would be to Import the Query and Form that I sent you into your database.
Create a New Command Button in YOUR form. Click on Report Operations
then Print Report. In the next screen, select YOUR Report that you want to print.
Make sure you type in your reports name in the NAME line in the properties section
of the print button. It needs to be Exactly like you have your report named. Then save all that.
Create a NEW Query and add the Table of the Report you're working on. Click on the Asterisk at the top and drag it down to the first Field Line. In the next line, add your ID# (I'm assuming you have one).
Go into Query design of the one I sent you. Copy the entire line in the Criteria line.
Paste that into your Criteria line and change the name of the form to the Name of YOUR form.
Save your Query any way you want. I name mine, example; Filter YourReport.
Go into Form Design of the file I sent you and double click on the Print Button.
Scroll down to the On Click line. Click to the right of that line. You'll see a small button
with three dots on it. Click on that button. Highlight the entire line of code that you see.
Then go to your form, double click on your print button, scroll down to the same line (On Click),
Click the small button to the right again, and paste the code there.
Replace Everywhere you see Incident with the name of YOUR report EXACTLY like your report
is named.
Replace where it says, Filter Incident with the name of your Filter exactly Like you have it named.
Exit out and save all that. You should be good to go now. IT'S THAT SIMPLE.
Thomas Bailey
a/k/a TomCat