Form [Not Report] - Print the Current Record

R

Robert T

Yes I know we're supposed to print reports, not forms, but my co-worker
manually prints a form with terrific graphics and it comes out looking great.
She doesn't want a report, she wants to print that pretty form and she only
wants to print the CURRENT record.

She asked me if I could create a button on the form that will print the
current record so she doesn't have to manually enter Page 33 through Page 33.
I know how to code this for a report, but I've never done it with a FORM and
I'm having trouble. Would someone be kind enough to get over the Print Only
from Reports advice and show me how to do this?

Note: The Primary Key is a TEXT field called FileNo.
 
R

Robert T

Hello Dave:

Here's the code I've tried. It prints the form, however, it doesn't capture
the current record, that's the hangup.

Dim MyForm As Form
Dim record_num As Long

stDocName = "frmTransactions"
Set MyForm = Screen.ActiveForm
DoCmd.SelectObject acForm, stDocName, True
record_num = MyForm.CurrentRecord
DoCmd.PrintOut acPages, record_num, record_num

Robert
-------------------------------------------------------------
 
R

Robert T

Hi:

That helped but it didn't solve the problem. Before, it kept printing the
same page, totally disregarding the current record. Now we're closer but it's
off by a couple of records. For example, when I was on Record Number 7, it
printed record number 4.

Does that give you any kind of clue?

Appreciate your help,
Robert
 
K

Klatuu

Record numbers are not meaningful and I don't know what your primary key
values are, but I suspect if you take out the from and to page numbers and
just try:

DoCmd.SelectObject acForm, "frmTransactions", True
DoCmd.PrintOut acSelected

It might work.

Let me know.
 
R

Robert T

Klatuu:

[DoCmd.SelectObject acForm, "frmTransactions", True
DoCmd.PrintOut acSelected


Is it AcSelected or AcSelection?

That was a good idea, however, it printed every record using acSelection and
acSelected. Any other thoughts?

Thanks,
Robert
 
K

Klatuu

Okay, I actually tested it and got it to work like this:

DoCmd.SelectObject acForm,"form2"
DocCd.PrintOut acSelection


--
Dave Hargis, Microsoft Access MVP


Robert T said:
Klatuu:

[DoCmd.SelectObject acForm, "frmTransactions", True
DoCmd.PrintOut acSelected


Is it AcSelected or AcSelection?

That was a good idea, however, it printed every record using acSelection and
acSelected. Any other thoughts?

Thanks,
Robert



Klatuu said:
Record numbers are not meaningful and I don't know what your primary key
values are, but I suspect if you take out the from and to page numbers and
just try:

DoCmd.SelectObject acForm, "frmTransactions", True
DoCmd.PrintOut acSelected

It might work.

Let me know.
 
R

Robert T

Dave:

It worked!

I owe you an apology because I was testing the script on my machine and I
guess the form on my computer wasn't in synch with this script. However, I
met with my co-worker after lunch and tried the code on her computer and it
worked perfectly! She's very excited and pleased becauses she loves printing
that form.

I told her that I still recommend copying the form to a report and printing
it that way, but for now, I don't want to argue with or change our formula
for success.

Thanks so much for your help,
Robert
 

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