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

Command on form to print only the displayed record

Status
Not open for further replies.

dcorleto

MIS
May 19, 2002
82
0
0
US
Have a form with search capability. Once I am on the record that I want to see on the form, How can I use a Command Button to print a report for that selected record only? When I click the command button it runs the report for all the records.

Thanks in advance
 
Have a look at the 4th argument of the DoCmd.OpenReport method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I believe I need a Where clause, but what syntax would I use so that only the current record would be printed from the report.
 
This works on a form that I am running. Just put it in a button in the on click event.

Private Sub Print_Sheet_Click()
On Error GoTo Err_Print_Sheet_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.PrintOut acSelection

Exit_Print_Sheet_Click:
Exit Sub

Err_Print_Sheet_Click:
MsgBox Err.Description
Resume Exit_Print_Sheet_Click

End Sub
 
Another solution which I have used with success can be found at thread702-1099854
 
or this...

Private Sub Command26_Click()
Dim strCriteria As String
strCriteria = "[mytable]![ID]=[Forms]![myform]![ID]"
DoCmd.OpenReport "myreport", acPreview, , strCriteria
DoCmd.PrintOut acPages, 1, 1, , 1
End Sub
 
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
 
Thanks Obli - Here's what I have based on your message:

Private Sub Print_Avid_Sheet_Click()


Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Workorder"
stLinkCriteria = "
Code:
 = " & Me![Code]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
    End Sub

What I get is the report to print out one page, but none of the record info is printed with it, just the blank form.  Am I getting any closer?
 
You may add the following line before opening the report:
DoCmd.RunCommand acCmdSaveRecord

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
DoCmd.RunCommand acCmdSaveRecord

This gave me an error saying Save Record command not available now
 
For some reason, none of these suggestions are working. The form is based on a query with expressions. Records cannot be added to the form or the query. Could this have something to do with why I am getting errors?

All I need to do is have the report print just the page for the record that I am on in the form. Can't imagine it require all this coding and be this difficult. Please help if you can. Thanks
 
Obli - Presto and another question ! Your idea worked as follows:

Private Sub Command85_Click()
Dim strCriteria As String
strCriteria = "
Code:
=[Forms]![Video Productions]![Code]"
DoCmd.OpenReport "Workorder", acPreview, , strCriteria
DoCmd.PrintOut acPages, 1, 1, , 1
End Sub

The form prints to the default printer which is fine, but I would like it to just close the print view and return back to the form.  Quick line of code to do this?

So So So many thanks!  DAN
 
This was also posted as:
Quick Answer? Print one record of a report based on dialog box filter
thread703-1234491
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top