views:

104

answers:

3

Is there anyway to determine the form name that the report was called from? I would like to write some VBA code in report to determine where is the report was called from. I have Access 2003.

+1  A: 

This is not possible unless you set it up yourself. You could write to a variable or, if the form remains open, store the information on the form.

Remou
Umm, if he doesn't know what form is opening the report how can he store the form name in the report?
Tony Toews
Sorry, but I do not get your point, I said store the information on the form if the form remain open, the forms can be checked from the report, or the form and report name are written to a variable, yesno?
Remou
+3  A: 

You can open a report like this:

DoCmd.OpenReport "reportFoo", acPreview, , , , Me.Name

and something like this in the report:

Private Sub Report_Open(Cancel As Integer)
    If "" <> Me.OpenArgs Then
        MsgBox Me.OpenArgs ' display caller form's name
    End If
End Sub
Nick D
I tested it on Ms Access 2003 before I post it.
Nick D
The OpenArgs parameter did not exist in Access before 2002, I think (not sure if it was in 2002, either -- it might have been introduced in 2003).
David-W-Fenton
+1  A: 

One way is to have a report_caller class that always opens any reports. It needs a method called "openReport" that takes in the name of the form doing the calling and the name of the report being opened. Then it can have a public method to allow the report to get the name of the form that was opened.

sql_mommy