Printing a single Record from a Form in a Report

Viper210

Registered User.
Local time
Yesterday, 19:08
Joined
May 10, 2012
Messages
14
I have a database, Form, and Report all named Intake3. I was successful in printing my report but Access prints all the records. I went to another Access site and found the following instructions that I attempted to modify to fit my database and command button:

The following procedure prints only the record that you select from the Customers form in the sample database Northwind.mdb.
1. Create a report based on the Customers table, and then name it rptPrintRecord.
2. Open the Customers form in Design view. Add a command button to the form, and then set the following command button properties:
3. Name: cmdPrintRecord4. Caption: Print Record5. OnClick: [Event Procedure] 6. Set the OnClick property to the following event procedure:
7. 8. Private Sub cmdPrintRecord_Click()9. 10. Dim strReportName As String11. Dim strCriteria As String12. 13. strReportName = "rptPrintRecord"14. strCriteria = "[CustomerID]='" & Me![CustomerID] & "'"15. DoCmd.OpenReport strReportName, acViewPreview, , strCriteria16. 17. End Sub 18. Open the form in Form view, and then Print Record. Note that the report preview is limited to the current record from the Customer form.

Please excuse my ignorance with both Access and VB but I had a couple of questions concerning these steps:

1. I don't know exactly how to enter steps 3,4,and 5 in the properties of the command button.

2. On step 13, I changed strReportName from "rptPrintRecord" to Mine "Intake3".

3. On step 14, I changed strCriteria from "CustomerID" to mine "ClientID"

4. In addition I can't figure out how to change the name of the button to "Print " . It currently says "Command53"

Here is what my code is right now under on click:

Private Sub cmdPrintRecord_Click()
Dim strReportName As String
Dim strCriteria As String

strReportName = "intake3"
strCriteria = "[ClientID]='" & Me![ClientID] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End Sub
Private Sub Command53_Click()
End Sub

Where am I Going wrong?
 
Are you getting an error, or is nothing happening.

There are two procedures in the code you posted, cmdPrintRecord_Click() and Command53_Click(). The latter has nothing in it. Make sure that the OnClick property is running cmdPrintRecord_Click().

Once you get it working, look for the Caption property to change the text on the button.
 
Thank you for your reply, After doing some additional research yesterday, I came to the same conclusion about the on click properties and got it to work. Here is the much cleaner code that I am using that will show the single record in the report:

Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ClientID] = " & Me.[ClientID]
DoCmd.OpenReport "Intake3", acViewPreview, , strWhere
End If
End Sub

What do I need to add to get it to add in order to get the record to print and not just display?
 
Apologies for my ignorance but where is the "Activate Property" of the report located?
 
Apologies for my ignorance but where is the "Activate Property" of the report located?

It's on the Property Sheet that you used to get to the code for the command button, except you need to select "Report" at the top so that you are looking at properties for the entire report. Once you have that view, select the Event tab to make it easier to find.
 

Attachments

  • propsheeet.JPG
    propsheeet.JPG
    59.6 KB · Views: 561

Users who are viewing this thread

Back
Top Bottom