Printing report from subform based on current record in main form

C

Clare

I have a comand button on my form which opens a popup containing a list of
reports to print. I have the following code which when placed on the main
form will use only the current record for the report.

Private Sub cmdPrintfees1_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ExternalExaminerID] = " & Me.[ExternalExaminerID]
DoCmd.OpenReport "RptFees,report", acViewPreview, , strWhere
End If
End Sub

But that won't work on my popup because of 'invalid use of the me.Dirty'

I have the following code which works in the popup and brings up the report,
but brings up a report for every record instead of just the current record.
The report list comes from a query using the MsysObjects table.

Private Sub lstReports_DblClick(Cancel As Integer)
ShowReports lstReports.Value, Forms!AMainform
End Sub

Function ShowReports(strReportName As String, frm As Form) As Integer
On Error Resume Next

Dim strWhereCond As String
strWhereCond = "MyField = " & frm!MyField

DoCmd.OpenReport strReportName, acViewPreview, , strWhereCond

If Err > 0 Then
'OpenReport failed
MyFunction = False
Else
MyFunction = True
End If
Exit Function
End Function

I admit I have just copied and pasted these and taken them from other help
topics so I don't actually completely understand it all. How do I make the
single record code work in the popup? Or how do I change the popup code to
take just the record that's in the main form?

Thanks very much.
 

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