Printing current record of a form

M

Mountaineer

Hi,

I have a form called f_Requests based on a table. In the form header are
combo boxes and command boxes to do a search critieria of the data. This
works great. But now I want to print this record.

My primary key is called "RequestNumber" which is an autonumber and is on
the form.

To create the report, while the form was in design mode, I selected "Save
As" -Report. I saved the report as r_Requests. The only items I deleted
from the report were the command buttons (my primary key field
"RequestNumber" is on the report).

Back on my form I added a command button cmdPrint. I added the following
code to the Click event (from Allen Browne "Print the record in the form").

Private sub cmdPrint_Click()

Dim strWhere as string

If Me. Dirty Then

Me.Dirty = false

End If

If Me.NewRecord Then

msgbox "Select a record to Print"

Else

strWhere="[RequestNumber]=" & me.[RequestNumber]
Docmd.OpenReport "r_Request", acViewPreview, strWhere

End IF

End Sub

On the form, I do my search. I get record 1 of 1. I click the Print
command button and it brings up a "Enter Parameter Value" box for "Form". I
do not have a parameter query as a part of my form so I do not know what is
it asking or why. If I click ok (leaving the parameter box blank), the
report previews but it previews with all records not just the single record.

I've tried putting the cmdPrint button in the form header and design section
and got the same results. I'm lost.

Any help would be appreciated.
 
M

Maurice

the code from Allen needs a parameter because that's what you are telling it
to ask for ( the where statement). So provide a id in the parameterbox and
your print will be filtered based on your choice. If you don't provide a
parameter you will get all records.
 
M

Mountaineer

Hi,

I appreciate the advice but I'm afraid I still didn't get it.

I thought the strWhere statement included my parameter id? I added a

Debug.print strwhere

statement. It returned [RequestNumber]=11 (which was my current record) but
I still got the parameter box.

--
Thank you!!

Mountaineer


Maurice said:
the code from Allen needs a parameter because that's what you are telling it
to ask for ( the where statement). So provide a id in the parameterbox and
your print will be filtered based on your choice. If you don't provide a
parameter you will get all records.
--
Maurice Ausum


Mountaineer said:
Hi,

I have a form called f_Requests based on a table. In the form header are
combo boxes and command boxes to do a search critieria of the data. This
works great. But now I want to print this record.

My primary key is called "RequestNumber" which is an autonumber and is on
the form.

To create the report, while the form was in design mode, I selected "Save
As" -Report. I saved the report as r_Requests. The only items I deleted
from the report were the command buttons (my primary key field
"RequestNumber" is on the report).

Back on my form I added a command button cmdPrint. I added the following
code to the Click event (from Allen Browne "Print the record in the form").

Private sub cmdPrint_Click()

Dim strWhere as string

If Me. Dirty Then

Me.Dirty = false

End If

If Me.NewRecord Then

msgbox "Select a record to Print"

Else

strWhere="[RequestNumber]=" & me.[RequestNumber]
Docmd.OpenReport "r_Request", acViewPreview, strWhere

End IF

End Sub

On the form, I do my search. I get record 1 of 1. I click the Print
command button and it brings up a "Enter Parameter Value" box for "Form". I
do not have a parameter query as a part of my form so I do not know what is
it asking or why. If I click ok (leaving the parameter box blank), the
report previews but it previews with all records not just the single record.

I've tried putting the cmdPrint button in the form header and design section
and got the same results. I'm lost.

Any help would be appreciated.
 

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