can't filter report open/preview from form

G

guilin

I have struggled on this for about a week.........

Have a command button to open/preview report from a form. I want it to
open the report for the current report. I used:

********Code start*********

Private Sub cmdPreviewInvoice_Click()
On Error GoTo Err_cmdPreviewInvoice_Click

Dim stDocName As String

stDocName = "rptPrintInvoice"
DoCmd.OpenReport stDocName, acPreview, "", InvoiceID =
Me.InvoiceID, acWindowNormal

Exit_cmdPreviewInvoice_Click:
Exit Sub

Err_cmdPreviewInvoice_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewInvoice_Click

End Sub

*******Code end***********

which opened the whole report without filtering. there's no error msg
Thanks for any advice!!!
 
A

Allen Browne

The WhereCondition must be a string made up of the field name with the value
concatenated:
DoCmd.OpenReport stDocName, acViewPreview, , "InvoiceID = " &
Me.InvoiceID

Without the quotes, if the form is on record 99, then what you previously
had becomes:
99 = 99
and that statement is true for all records.
 
M

Mark via AccessMonster.com

Put the "Where Condition" in quotes. Also, you don't need the null string ("") in the placeholder after the "acPreview" clause; just the commas are enough. By the same token, the "acWindowNormal" at the end is the default, so you really don't need to include it.

DoCmd.OpenReport stDocName, acPreview, "", InvoiceID = Me.InvoiceID, acWindowNormal

should be

DoCmd.OpenReport stDocName, acPreview, , "[InvoiceID] = " & Me.InvoiceID
 

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