Calling a form on report close action.

  • Thread starter Thread starter NEMO2K
  • Start date Start date
N

NEMO2K

Hi All,

if there's somebody out there who can help me in solving
the following problem, I'd be very grateful.
I need to open a report from several forms and, once the
report is closed to go back to the calling form. The form
must not be closed when report opens (only minimize or not
visible). I tryed to pass to an hidden control in the
report the Screen.ActiveForms.Name property but I get
always an error from the system which doesn't let me pass
this value to the opening report. If I could store this
value in a variable I could call it on report close action.
I would greatly appreciated any suggestion.
Thanks,

NEMO2K.
 
The simplest thing to do would be to leave the form open behind the report.
When you close the report, voila: there is your form.

If you are using Access 2002 or later, you could pass the name of the form
in the OpenArgs of OpenReport. Then in Report_Close you can show the form
with:
Forms(Me.OpenArgs).SetFocus
In earlier versions you could use a public string variable to store the name
of the form, read that into a variable in Report_Open, and then use the
variable in Report_Close.
 
Hi Allen,

as the calling is a pop-up form, it will be always on top
and I'm compelled to move it manually with mouse if I want
to see the below report preview. I'm using A97 version:
where should I declare the public variable to store the
form name? Are you so kind to explain me the correct
procedure?
Thanks in advance,

NEMO2K
 
In a standard module (on created through the Modules tab of the Database
window), enter this in the General Declarations section (at the top, with
the Option statements):
Public gstrCallingForm As String

In the code that opens the report:
gstrCallingForm = Me.Name
DoCmd.OpenReport "MyReport", acViewPreview
Me.Visible = False

In the General Declaration section of the report's module:
Dim mstrCallingForm As String

In the Open event procedure of the report:
Private Sub Report_Open(Cancel As Integer)
mstrCallingForm = gstrCallingForm
gstrCallingForm = ""
End Sub

In the Close event procedure of the report:
Private Sub Report_Close()
If Len(mstrCallingForm) > 0 Then
If IsLoaded(mstrCallingForm) Then
Forms(mstrCallingForm).SetFocus
End If
End If
End Sub

Copy the IsLoaded() function from the Utility module of the Northwind sample
database.

You might be able to get away without the module level variable in the
report, but that approach will cope with multiple forms and reports opening
and closing at the same time.
 
Back
Top