home

Forms:Print Current Record

6/13/01 10:38:23 AM
This example is for printing the same record as your form is showing when the form is showing one record at a time, and you wish to print that 1 single record. If you have a continuous form--spreadsheet-style--showing multiple records, and you wish to print a report based on that form, then go here.

You could always use the "File....Print" option when your form is currently showing the record(s) you want printed. However, this typically does not produce very attractive results. It's better to design a button to take care of this.

To put a button on the form which will print the current record, first, design the report and base it on the table/query which normally shows all the records. Then create a command button on the form and type in the code below (of course, edit it to reflect your own databases' field/report names):

Private Sub Command33_Click()
Dim sSQL As String
DoCmd.RunCommand acCmdSaveRecord 'Saves the record so it is available to print even if it was just added right now
sSQL = "[autoid]=" & Me.autoid
DoCmd.OpenReport "samples_report_1", acViewPreview, , sSQL
End Sub

The above code assumes a report name of samples_report_1, and it identifies each record by the autoid field.