Fred.
Thanks for the code. However, I need to tweak it a little and need your
help again.
I guess because the report is based on a query, the query opens and I
have
to type in the project number (that's what the query is based on).
I tried making a copy of the report and making it dependent on the table
only, thereby eliminating the need to put in the project number, but that
creates some other problems, as the information in the report is drawn
from
a few different tables. So when the command executes, it begins asking
for
information that is contained in the other tables, that information being
info I couldn't possibly remember to be able to input.
So I guess my question is how do I modify the code to have the command
button transfer the project number (which is the same as RecordID in your
code) into the query so that it can automatically generate the report.
Either that or how do I fix it so that I don't have to remember all of
the
other information to make the report come out right (I guess make it pull
up
the information automatically, as it does in the query version)
One last question... When the report actually does come up (in the query
version), it is opened in the background, and I have to minimize
everything
else to view it. Any way to make it open on top of everything else?
I hope my questions make sense. And I really really appreciate your
help.
I am learning, albeit slowly via the help of others and mainly through
trial
and error.
Thanks again,
Tom Pratt
fredg said:
On Wed, 28 Feb 2007 14:36:30 -0500, FIECA wrote:
Question: I have a form which provides details on projects my company
has
been awarded. I have also formulated a report to provide the same
details
in a printed form. Is there a way to create a button on the form to
print
the report using the information currently displayed (or the
information
for
the current record), as opposed to having to exit the form and then
open
the
report and print it.
Any help would be greatly appreciated.
Thank you,
Tom Pratt
Your table should have a unique prime key field.
In my example it is named [RecordID].
Add a command button to your form.
On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]
The above assumes a [RecordID] field that is a Number Datatype.
If, however, [RecordID] is Text Datatype, then use:
DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"
as the Where clause.
For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "
Change [RecordID] to whatever the actual field name is that you are
using.
See VBA Help files for:
Where Clause + Restrict data to a subset of records'