Printing a Report from a Form

C

Chip Melton

I am trying to print a Report from a button on a Form but i am using the
field 'SAVNUM' (SAV #) as the filter criteria. This way when someone is
looking at SAV # 4 on the form and hit the print button it prints out only
the Report for SAV# 4. Here is the code i am using, but when i hit the
print button it print-previews all the reports. Is there something i need
to do to the Query?

Private Sub Command20_Click()
On Error GoTo Err_Command20_Click

Dim stDocName As String

stDocName = "rpt_SAV"

DoCmd.OpenReport stDocName, acViewPreview, , SAVNUM = Me.SAVNUM

Exit_Command20_Click:
Exit Sub

I am just leaning VB so it is probably a simple mistake i have made!!!!

---- THANKS in advance!!!
 
F

Fredg

Chip said:
I am trying to print a Report from a button on a Form but i am using the
field 'SAVNUM' (SAV #) as the filter criteria. This way when someone is
looking at SAV # 4 on the form and hit the print button it prints out only
the Report for SAV# 4. Here is the code i am using, but when i hit the
print button it print-previews all the reports. Is there something i need
to do to the Query?

Private Sub Command20_Click()
On Error GoTo Err_Command20_Click

Dim stDocName As String

stDocName = "rpt_SAV"

DoCmd.OpenReport stDocName, acViewPreview, , SAVNUM = Me.SAVNUM

Exit_Command20_Click:
Exit Sub

I am just leaning VB so it is probably a simple mistake i have made!!!!

---- THANKS in advance!!!
Chip,
The Where clause must be a string.
DoCmd.OpenReport stDocName, acViewPreview, , "SAVNUM = " & Me.SAVNUM
Note the position of the last ". The above assumes [Savenum] is a Number
dattype.

If it were text then use:
"SAVNUM = '" & Me.SAVNUM & "'"

See Access help files for
Where clause + restrict data to a subset of records
 

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