Results 1 to 3 of 3

Thread: Calling a Sub

  1. #1
    JamesP
    Guest

    Calling a Sub

    Can a Private Sub in the module of a form be called from another form module?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Calling a Sub

    Nope. That's what private means, it can only be seen and used by the other routines within that object. If you declare a form routine as public, there are several ways to call it from outside a form.

    One way is to fully reference the open form like this: Forms!Orders.Form.ListNames

    Or another other way is to call the routine as a member of the form's module like this: call [Form_Orders].ListNames

    Even if the form isn't open, you can still call the procedure by setting an object variable like this:
    Dim frm As New [Form_Orders]
    frm.ListNames

    Here's a sample of routine that is outside the form calling a pubic sub in the form:

    Public Function TestFormCall()
    [Form_fmnuListProc].cmdList_Click
    End Function
    Charlotte

  3. #3
    JamesP
    Guest

    Re: Calling a Sub

    PERFECT! Exactly what I was looking for.

    Thanks again Charlotte![img]/w3timages/icons/grin.gif[/img]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •