Runtime error 2467

G

Guest

I have a pop up form that grabs some parameters and then opens a report.
When I open the report I hide the form (me.visible = false) and make a call
to a module that sets a property for the form being hidden (all this happens
before the report is actually opened). That works fine. When I close the
report I make the form visible again. No problem doing this either. My
problem happens when I close Access via the RED X button in the upper right
hand corner. I get the runtime error of 2467 that basically tells me that
the object (CallingForm) doesn't exist.

In the report close event I put I have the following statement:

If Not CallingForm is Nothing then
CallingForm.Visible = True
End If

CallingForm is the property in my module that is set (I do use Set property)
right before the call to open the report.

From what I can tell, when I close Access within the report object, then all
other objects are closed before the report object is closed. Therefore, when
the close event for the report object fires there is no CallingForm object
and thus the runtime error occurs. So, how do I hide a form and then make it
visible when the report closes via a normal report close event yet handle the
case where the report is open when Access closes.

Thanks,

Burnsie
 
B

Bill Manville

Burnsie said:
If Not CallingForm is Nothing then
CallingForm.Visible = True
End If

Simple way:
On Error Resume Next
CallingForm.Visible = True
On Error Goto 0 ' or to your procedure's error handler if it has one

More elegant way?:
I would store the name of the form (in stCallingForm) rather than the
object pointer and use a function I always use to test for existence of
an object:

Function IsIn(oCollection As Object, stName As String) As Boolean
Dim O As Object
On Error Goto NotIn
IsIn=False
Set O=oCollection(stName)
' if it gets here the object exists
IsIn=True
NotIn:
End Function

then
If IsIn(Forms, stCallingForm) Then
Forms(stCallingForm).Visible=True
End If

Bill Manville
MVP - Microsoft Excel, Oxford, England
 
G

Guest

Bill,

Thanks so much. This is exactly what I needed. Obviously, I was checking
for the existence of the object and assuming it was available (either with a
value or nothing). I did not consider the fact that it did not exist at all
and therefore, did not provide an error handler.

Your snippet will definitely be useful in so many other ways.

Thanks again.

Burnsie
 

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