Forum Discussion
Print a single record report from a button on a form
Hello,
I am converting a database from Paradox to Access. I have limited Access experience. I am trying to print a single record on a report launched from a button on the form. I duplicated some code I found on another forum changing the form name, report name and field. When I press the button the report launches but it is blank, no output. The code I used is below. UNIT is the data field for the data and each record has a unique number. UNIT is not the primary key.
Option Compare Database
Private Sub Command394_Click()
End Sub
Private Sub command399_Click()
DoCmd.OpenReport "FLEET-MACHINE DATA SHEET", acViewPreview, , _
"[UNIT]=Forms!frmFLEET_MASTER_DEVELOP"
End Sub
Private Sub Print_Machine_Detail_Click()
End Sub
Blank output below.
I tried modifying the code:
Option Compare Database
Private Sub Command394_Click()
End Sub
Private Sub command399_Click()
DoCmd.OpenReport "FLEET-MACHINE DATA SHEET", acViewPreview, , _
"[UNIT]=Forms!frmFLEET_MASTER!UNIT" '""
End Sub
Private Sub Print_Machine_Detail_Click()
End Sub
This launches a box which allows me to input the unit # and output to the report. I would like to code it so the user does not have to input any variable to run the report.
- Try
DoCmd.OpenReport "FLEET-MACHINE DATA SHEET", acViewPreview, , "[UNIT]=" & Me.Unit
- Try
DoCmd.OpenReport "FLEET-MACHINE DATA SHEET", acViewPreview, , "[UNIT]=" & Me.Unit- gregm57Copper Contributor
Thanks for the coding, it works better but still requires the user to input the unit number. Is there a way to print the record selected on the form without user input?
I found another issue, I have a number of machines in inventory where the stock number has a dash "-" in it. this causes the button to fail.
Thanks again for the assistance, it is very helpful for a neophyte such as myself.
- One other comment, I usually check if the record needs to be saved prior to opening a report to ensure it is up-to-date, so before using the DoCmd.OpenReport, you may like to add If Me.Dirty = True Then Me.Dirty = False