calling Sub in Module

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • questionit
    Contributor
    • Feb 2007
    • 553

    calling Sub in Module

    If you write a Sub/Function , called "ASub" in a module and call the module "Module2"

    If from the form, a button is clicked, how can i call "ASub"
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Module2
    [code=vb]
    Option Compare Database
    Option Explicit

    Public Sub ASub()
    MsgBox "You just called ASub in Module 2"
    End Sub
    [/code]

    Command_Click()
    [code=vb]
    Private Sub Command_Click()
    Call ASub
    End Sub
    [/code]

    Comment

    • questionit
      Contributor
      • Feb 2007
      • 553

      #3
      any idea why i am getting error:

      "Sub of Function not defined"

      i have similar way to yours

      Originally posted by JKing
      Module2
      [code=vb]
      Option Compare Database
      Option Explicit

      Public Sub ASub()
      MsgBox "You just called ASub in Module 2"
      End Sub
      [/code]

      Command_Click()
      [code=vb]
      Private Sub Command_Click()
      Call ASub
      End Sub
      [/code]

      Comment

      • questionit
        Contributor
        • Feb 2007
        • 553

        #4
        Its works now...... I made Sub Private before,.
        Originally posted by questionit
        any idea why i am getting error:

        "Sub of Function not defined"

        i have similar way to yours

        Comment

        • questionit
          Contributor
          • Feb 2007
          • 553

          #5
          HI

          If in the module code, i have to refer to a textfield located on a form, how would i do that.

          for example, a form is called:
          my_form

          It has a textfield , TextBox0

          In the module code, i have to set value of TextBox0.... I cant do Me.TextBox0

          I have tried doing my_form.TextBox 0 - but doth the ways seems not to work


          help!
          thanks


          Originally posted by questionit
          Its works now...... I made Sub Private before,.

          Comment

          • Lysander
            Recognized Expert Contributor
            • Apr 2007
            • 344

            #6
            Originally posted by questionit
            HI

            If in the module code, i have to refer to a textfield located on a form, how would i do that.

            for example, a form is called:
            my_form

            It has a textfield , TextBox0

            In the module code, i have to set value of TextBox0.... I cant do Me.TextBox0

            I have tried doing my_form.TextBox 0 - but doth the ways seems not to work


            help!
            thanks
            Simplest way would be to have your code in the forms module, rather than a global module. That way, the code can refer directly to TextBox0

            If the code has to be global (because it is called from many forms) then pass TextBox0 as a variable to the code, byRef, so it can be changed.
            i.e.
            [code=vb]
            sub mycode (byRef textbox as string)
            [/code]

            Comment

            Working...