Report to print current record only

G

Guest

I have a table and form containing corporate customer details.
I have designed a report that will provide a hard copy of these.
In the underlying Query I have set the criteria to [Corpname] so that there
is a dialogue box for the user to specify which customer details are to be
printed out.
However, if the user was "in" that particular customer record it would be
far nicer if he/she didn't have to type the name in, i.e. if the system could
just recognise which is the current record and go ahead and print without
asking via a dialogue box.
I have used the built-in command button for firing the report.
How would I modify the code for this, to make it look at the current record
and print just that one?
Many thanks
CW
 
G

Guest

No response needed after all - I found an excellent explanation from fredg on
an earlier post, works perfectly, thanks.
CW
 
A

Al Campagna

CW,
Assuming that your report is designed to print ALL records, it is possible, when you
call the report, to refer to the current/open form provide the value used to filter that
report.
Let's say your form is named frmCorporations, and the control with the Corporation name
is called CorporationName
Replace your [CorpName] parameter in the report query to...

=Forms!frmCorporations!CorporationName

The report will only print that corporations record...
--------------------------------------------
Note: a couple of suggestions....
1. Don't use CorporationName to filter the report. Imagine if this was an Name &
Address database... there would be a good chance that there might be duplicate Names.
(you may not have any duplicate Corps "now", but it's poor design to use a field that is
"susceptible" to dupes for filtering or identifying)
You may someday have ABC Corporation in New York and an ABC Corporation in New Jersey.
Each Corporation record should have a unique identifying key field, like
CorporateID, and that's the field you should be using to find records, or filter your
report for "One" corporation and "One" corporation only.

2. Because your report has a parameter in the query, it can only be used to print one
record. There's a way you can filter the report in the OpenReport method... (remove the
parameter in the query when you try this - code all on one line)
DoCmd.OpenReport "rptCorporations",,, "[CorporationName] =
Forms!frmCorporations!CorporationName"
This will filter the report using value on the form via the "Where" argument of the
OpenReport method.

Using the Where argument of OpenReport, rather than your "parameter" query method, the
report is capable of printing ALL corporations, OR... just one, according to how you call
it.
Here's how to call ALL corporations with the very same report.
DoCmd.OpenReport "rptCorporations"

Now, as a new user, this may be a bit daunting, so don't get too hung up my additional
suggestions. Use whatever method you feel more comfortable with. I added the suggestions
just for additional info.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."

CW said:
I have a table and form containing corporate customer details.
I have designed a report that will provide a hard copy of these.
In the underlying Query I have set the criteria to [Corpname] so that there
is a dialogue box for the user to specify which customer details are to be
printed out.
However, if the user was "in" that particular customer record it would be
far nicer if he/she didn't have to type the name in, i.e. if the system could
just recognise which is the current record and go ahead and print without
asking via a dialogue box.
I have used the built-in command button for firing the report.
How would I modify the code for this, to make it look at the current record
and print just that one?
Many thanks
CW
 

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