Print Current Record

  • Thread starter Thread starter DB
  • Start date Start date
D

DB

I'm trying to create a command button on an Access 2000
form that will allow an end user to open a report, print
the current record then close the report and return to
the form so they may continue their input. I tried
several ways to create a macro using OpenReport however
it either prompts me to enter the field name or it prints
all pages EXCEPT the current record. Either way, I
receive "#Error" in the field and the rest of the report
is blank.
 
It should be simple, from a form, to open a report and print the current
record -- I've done it too many times for there to be anything inherently
wrong with it.

Use the Command Button Wizard to add a Command Button to the Form to
"Preview Report"... that will get you the basic structure of your code in
the Click event, including a DoCmd.OpenReport but without a WhereCondition
argument to limit the records. Add your own VBA code, prior to the
DoCmd.OpenReport, to create the "WHERE condition without the WHERE" as
required by the DoCmd.OpenReport (it's well-documented in Help). That might
look something like this

Dim strWhere as String
....
strWhere = "[MyRecdIDField] = " & Me!txtRecordID
...
DoCmd.OpenReport "yourreportname",acViewPreview,,strWhere

Use the names of your own objects. The WHERE was built on the assumption of
a numeric ID. You'll need some additional quote marks if it is a text field.

Larry Linson
Microsoft Access MVP
 
#Error in what field? On the Report? In the Form?

Use VBA.
Code a command button on the report:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName",acViewPreview, , "[RecordID] = " & [RecordID]

where [RecordID] is the name of the unique prime key field of the record.
The above assumes [RecordID] is a Number Datatype.
If [RecordID] is a Text datatype field, then use:

[RecordID] = '" & [RecordID] & "'"

Change [RecordID] to whatever the actual name of that field is.
Change acViewPreview to acViewNormal to print without previewing the report.

When you display the record to be printed, click the command button.
Only that record will be in the report.
 
Back
Top