L
Lyle Davis
I want to generate a report from a form, but I only want the current record
to be on the report
to be on the report
Jeff Boyce said:Lyle
Forms are great for displaying (and entering) records. Reports are intended
to print out information. Wouldn't you rather generate a report based on
the underlying data/record that you are displaying in a form?
You can create a report based on the same query you use to feed your form.
In your form, you can add a <Print Report> command button that opens the
report, using the "current record" (the one the form is displaying) as a
filter for the report.
Regards
Jeff Boyce
<Office/Access MVP>
Lyle Davis said:I want to generate a report from a form, but I only want the current
record
to be on the report
Larry Linson said:Lyle Davis said:I want to generate a report from a form, but I only want the current
record
to be on the report
To create a report based on a Form, with the Form open in Design View, on
the menu File | Save As and in the Dialog, under "As", choose Report. Then
open the Report in Design View, and alter it, if need be, so that it is for
displaying information rather than entering/altering information as Forms
often are (like eliminate the colored background so it looks like a printed
document, etc.).
To run that Report from the Form, be sure you have the Fields that uniquely
identify the Record available. Using the Command Button Wizard create a
Command Button to Run the Report.
Then back to design view of the Form, select the newly-created Command
Button, right-click to show Properties, choose Events, click to open the
code for the Click event. In that code you will find DoCmd.OpenReport. Move
the I-beam cursor over that command and click to put it there, then press
F1.
In Help for DoCmd.OpenReport, you'll see "WhereCondition"... you need to
create a WhereCondition argument using the unique record identifier to
select the Record.
The code might look something like this, if the Field were "CustomerID" and
it were displayed in the TextBox called txtCustomerID:
Dim strWhere as String
strWhere = "[CustomerID] = """ & Me.txtCustomerID & """"
and the DoCmd.OpenReport would be modified to read:
DoCmd.OpenReport stDocName, acPreview, strWhere
If you know VBA fairly well, I apologize for going into such detail, but
thought you might be new to VBA and need each step.
Larry Linson
Microsoft Access MVP
Larry Linson said:Lyle Davis said:I want to generate a report from a form, but I only want the current
record
to be on the report
To create a report based on a Form, with the Form open in Design View, on
the menu File | Save As and in the Dialog, under "As", choose Report. Then
open the Report in Design View, and alter it, if need be, so that it is for
displaying information rather than entering/altering information as Forms
often are (like eliminate the colored background so it looks like a printed
document, etc.).
To run that Report from the Form, be sure you have the Fields that uniquely
identify the Record available. Using the Command Button Wizard create a
Command Button to Run the Report.
Then back to design view of the Form, select the newly-created Command
Button, right-click to show Properties, choose Events, click to open the
code for the Click event. In that code you will find DoCmd.OpenReport. Move
the I-beam cursor over that command and click to put it there, then press
F1.
In Help for DoCmd.OpenReport, you'll see "WhereCondition"... you need to
create a WhereCondition argument using the unique record identifier to
select the Record.
The code might look something like this, if the Field were "CustomerID" and
it were displayed in the TextBox called txtCustomerID:
Dim strWhere as String
strWhere = "[CustomerID] = """ & Me.txtCustomerID & """"
and the DoCmd.OpenReport would be modified to read:
DoCmd.OpenReport stDocName, acPreview, strWhere
If you know VBA fairly well, I apologize for going into such detail, but
thought you might be new to VBA and need each step.
Larry Linson
Microsoft Access MVP
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.