Need Help Checking MdiParent on Form Open event from a module

  • Thread starter Thread starter The Mad Ape
  • Start date Start date
T

The Mad Ape

Hi

Whenever I open a form and want to check for an existence of the form
I use the following code:

Dim frm As Form
For Each frm In Me.MdiParent.MdiChildren
If TypeOf frm Is Form17 Then
frm.Close()
End If
Next

However when this same code is placed in a module it does not work as
'Me' throws an error:
Me is not valid withing a module.

How do I overcome this?

Thanks in advance.
 
The Mad Ape said:
Hi

Whenever I open a form and want to check for an existence of the
form I use the following code:

Dim frm As Form
For Each frm In Me.MdiParent.MdiChildren
If TypeOf frm Is Form17 Then
frm.Close()
End If
Next

However when this same code is placed in a module it does not work
as 'Me' throws an error:
Me is not valid withing a module.

How do I overcome this?

Get rid of the Module. Move the code into the MDIParent. If you need to
call it from outside, put it into a Public Sub. If there can be only one
instance of Form17, declare a variable of that type, so you won't have
to search for it.


Armin
 
Get rid of the Module. Move the code into the MDIParent. If you need to
call it from outside, put it into a Public Sub. If there can be only one
instance of Form17, declare a variable of that type, so you won't have
to search for it.

Armin

I did what you said but now when I call it as follows:

AddHandler tabLblPulp.Click, AddressOf GetStandVol 'where GetStandVol
is the name of the sub and tabLblPulp is a programmatcially created
label that I wish to put code behind the click event.

I am getting and error that GetStandVol is not declared, even though I
declared it as a public sub in the parent form. What is up with that?

Thanks
 
I did what you said but now when I call it as follows:

AddHandler tabLblPulp.Click, AddressOf GetStandVol 'where GetStandVol
is the name of the sub and tabLblPulp is a programmatcially created
label that I wish to put code behind the click event.

I am getting and error that GetStandVol is not declared, even though I
declared it as a public sub in the parent form. What is up with that?

Thanks

Never mind. I just replaced AddressOf GetStandVol with AddressOf
Form1.GetStandVol where Form1 was the form that the Public resides.

Thanks
 
Back
Top