Need Help Checking MdiParent on Form Open event from a module

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.
 
A

Armin Zingler

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
 
T

The Mad Ape

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
 
T

The Mad Ape

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
 

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