can't open report on current record

G

George

Hi I need help
I have a report that populates from a query and I want the report to open on
the current record basede on the form and subform current fields.
My code is as follows

Private Sub btnPrintReport_Click()
On Error GoTo Err_btnPrintReport_Click

Dim stDocName As String

stDocName = "Agreement"
Dim strWhere As String
If Me.Dirty Then 'save first
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select the record to print."
Else

strWhere = "[Customers_CustomerID] = " & Forms![ProjectsAll]![Customers
Subform].Form![Customers_CustomerID]
DoCmd.OpenReport stDocName, acViewPreview, , strWhere
End If

Exit_btnPrintReport_Click:
Exit Sub

Err_btnPrintReport_Click:
MsgBox Err.Description
Resume Exit_btnPrintReport_Click

End Sub

Any help greatly appreciated
Thanks
 

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