Need Help Checking MdiParent on Form Open event from a module

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Mad Ape

    #1

    Need Help Checking MdiParent on Form Open event from a module

    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.Md iChildren
    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.
  • Armin Zingler

    #2
    Re: Need Help Checking MdiParent on Form Open event from a module

    "The Mad Ape" <chiefape@gmail .comschrieb
    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.Md iChildren
    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

    Comment

    • The Mad Ape

      #3
      Re: Need Help Checking MdiParent on Form Open event from a module

      On Apr 12, 11:28 am, "Armin Zingler" <az.nos...@free net.dewrote:
      "The Mad Ape" <chief...@gmail .comschrieb
      >
      >
      >
      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.Md iChildren
      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
      I did what you said but now when I call it as follows:

      AddHandler tabLblPulp.Clic k, AddressOf GetStandVol 'where GetStandVol
      is the name of the sub and tabLblPulp is a programmatciall y 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



      Comment

      • The Mad Ape

        #4
        Re: Need Help Checking MdiParent on Form Open event from a module

        On Apr 12, 11:38 am, The Mad Ape <chief...@gmail .comwrote:
        On Apr 12, 11:28 am, "Armin Zingler" <az.nos...@free net.dewrote:
        >
        >
        >
        "The Mad Ape" <chief...@gmail .comschrieb
        >
        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.Md iChildren
        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
        >
        I did what you said but now when I call it as follows:
        >
        AddHandler tabLblPulp.Clic k, AddressOf GetStandVol 'where GetStandVol
        is the name of the sub and tabLblPulp is a programmatciall y 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.GetStandV ol where Form1 was the form that the Public resides.

        Thanks

        Comment

        Working...