Experts Don't Fail Me Now!

G

Guest

I have a form with demographic info shown on the top for a record. On the
bottom is a series of file tabs showing additional info. I want to be able to
print the page that you are looking at both the demo at the top and the info
on the tab below.

I was given this basic for printing one page, and I thgought that it worked,
but all it does is print the first record not the page that you are viewing.

DoCmd.PrintOut acPages ,1,1

Does anyone know how I can print the record I am viewing top and bottom.
Thanks
 
G

Guest

Forms are really not designed for printing. The correct approach would be to
create a report that presents the data for the record you want to print. The
open the report using the OpenReport method. Filter the report using the
Where argument to filter it so only the current record is printed.
 
G

Guest

I have heard that before, and I have already created a report, but when your
boss wants to print what he is looking at you have to try. So, I guess there
is no other way to do it.

Can your tell me how to filter it so only the current record is printed?
Thanks
 
G

Guest

Sometimes it is necessary to convince your boss you are acting in his/her own
best interest.
The compromise would be to lay the report out as close to the design of the
form as possible.

To filter the form, use the Where argument of the OpenReport method. See
VBA Help for details, but basically, you use the primary key value of the
current record. It is exactly like an SQL WHERE statement without the word
where. You use the name of the field in the record source of the report and
the name of the control on your form to give it the value:

Docmd.OpenReport "rptSomeReport", , , "[PrimeKeyField] = " &
Me.txtPrimeKey

The names are made up, use your own.
In this case, [PrimeKeyField] would be the name of the field in the report's
record source that stores the record's primary key. Me.txtPrimeKey is the
name of a text box on the form that is bound to the field [PrimeKeyField] in
the table/query.

One other thing to be aware of. If the current record has not been saved,
your report will error because if the record is new, it is not in the table
yet or if it is an existing record that has not been saved, the report will
reflect the old data.


Put this before the open report to ensure the data is current:

If Me.Dirty Then
Me.Dirty = False
End If
 

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