To generate a report from a form

L

Lyle Davis

I want to generate a report from a form, but I only want the current record
to be on the report
 
J

Jeff Boyce

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>
 
L

Lyle Davis

Exactly how do I do that?

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>
 
L

Larry Linson

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
 
A

Ang

I borrowed this answer for a form that has 6 drop down boxes. They are not
nested, just different fields that a user might use to filter.

It works great when I have the code in the sub of the btn click procedure
where the final line is the open report command.

When I added a second button I copied all the code into it's procedure and
for the third. Now that I am looking at a fourth button and could have
additional drop down boxes, it seems that maybe I should have the strwhere
code in a module or something so that it can be called rather than typed and
edited in each button code.

Suggestions?

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
 
M

Mabeline

Hi Larry,

I am trying to do a similar thing to this but I have a separate form with
only one field. This field is an unbound text box that allows the user to
enter a tag number I then want to generate a report after they press enter
that will display all of the records from a single table that match this tag
number. The code I have written keeps brining all of the records from the
table even if the tag numbers don't match. Can you help me also so that I can
display this report. I am using an event procedure to do this.

Thanks in advance.


Mabeline

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
 

Ask a Question

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.

Ask a Question

Top