Printing Report for One Record

D

Dan

I attached a button to a form for the purpose of printing
a report. I would like to set it up so that the report
contains only the data for the current record on that
form. Any ideas?
Thanks.
 
C

Cheryl Fischer

Try this:

DoCmd.OpenReport "MyReport", , , "ID = " & Me.ID

Change ID to whatever field/control will uniquely identify the record you
want to print.


hth,
 
G

Guest

The following is what is in the code and it still printed
all the records. Is there something else missing?

Private Sub Print_w_memo_Click()
On Error GoTo Err_Print_w_memo_Click

Dim stDocName As String

stDocName = "rQuote"
DoCmd.OpenReport stDocNum, , , "QuoteName = " &
Me.QuoteNum

Exit_Print_w_memo_Click:
Exit Sub

Err_Print_w_memo_Click:
MsgBox Err.Description
Resume Exit_Print_w_memo_Click

End Sub
 
C

Cheryl Fischer

Are you sure that the code ran without error?

You have declared a variable: stDocName and assigned the value rQuote
to it, presumably the name of your report. However, your DoCmd.OpenReport
is attempting to open stDocNum

Also, in your expression: "QuoteName = " & Me.QuoteNum - If QuoteNum is
a text type field, you must pass it so that it is evaluated with quotation
marks around it,

"QuoteName = " & Chr(34) & Me.QuoteNum & Chr(34)
 
D

Dan

Your subsequent reply comes back "message unavailable"
Can you resend or send direct to my email address?

Thanks
 
C

Cheryl Fischer

Resent:

Are you sure that the code ran without error? <g>

You have declared a variable: stDocName and assigned the value rQuote
to it, presumably the name of your report. However, your DoCmd.OpenReport
is attempting to open stDocNum

Also, in your expression: "QuoteName = " & Me.QuoteNum - If QuoteNum is
a text type field, you must pass it so that it is evaluated with quotation
marks around it,

"QuoteName = " & Chr(34) & Me.QuoteNum & Chr(34)
 
Top