Results 1 to 11 of 11

Thread: Calling a forms Public routine

  1. #1

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Resolved Calling a forms Public routine

    I want to call a forms public routine (of my own making) and I want to do it dynamically by using the forms collection. I can't seem to make it work

    Ex.
    Code:
    Dim frm as Form
    
    For Each frm in Forms
    
       If frm.Visible Then CallByName frm, "ResizeForm", VbMethod
    
    next
    Any solutions?

    The only way this works is if I substitute the frm for the actual form name (being it's an object) in the CallByName call.
    Last edited by randem; Aug 2nd, 2007 at 01:29 AM.

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Calling a forms Public routine

    That should work as long as all forms have a public sub called ResizeForm.

  3. #3
    Addicted Member Jazz00006's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Re: Calling a forms Public routine

    Code:
    Private Sub Command1_Click()
          Dim Frm            As Form
          For Each Frm In Forms
                If Frm.Visible Then ResizeForm Frm
          Next
    End Sub
    
    Public Function ResizeForm(Frm As Form)
          With Frm
                .Top = 500
                .Left = 500
                .Width = 500
                .Height = 500
          End With
    End Function
    Taking a wild guess

  4. #4

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Calling a forms Public routine

    Jazz00006,

    That would work if each form did not have it's own resize function. Each form has it's own resize function and it needs to be called.

  5. #5
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Calling a forms Public routine

    vb Code:
    1. Private Sub Command1_Click()
    2. Dim frm As Form
    3. For Each frm In Forms
    4. If frm.Visible = True Then frm.resizeform
    5. Next frm
    6. End Sub

    works fine as long as each form has that particular function. Which from what you just said seems like each does

  6. #6
    Addicted Member Jazz00006's Avatar
    Join Date
    Feb 2006
    Posts
    185

    Re: Calling a forms Public routine

    Sorry, thought it was a custom function <_< should read things more thoroughly more often

    Glad you fixed your problem too.

  7. #7

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Calling a forms Public routine

    Hell-Lord,

    That was the first thing I tried... No Joy!!!

  8. #8
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Calling a forms Public routine

    That is odd works fine for me...

  9. #9

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Calling a forms Public routine

    Quote Originally Posted by Hell-Lord
    vb Code:
    1. Private Sub Command1_Click()
    2. Dim frm As Form
    3. For Each frm In Forms
    4. If frm.Visible = True Then frm.resizeform
    5. Next frm
    6. End Sub

    works fine as long as each form has that particular function. Which from what you just said seems like each does
    Nope, I get "Object does not support this method" on frm.ResizeForm

    But I did find a way:

    Code:
    Dim i As Long
    
        For i = 1 To Forms.Count - 1
    
                If Forms(i).Visible Then CallByName Forms(i), "ResizeForm", VbMethod
    
        Next i
    Thanks for your input guys.

  10. #10
    New Member
    Join Date
    Oct 2009
    Posts
    2

    Unhappy Re: Calling a forms Public routine

    I am having this same exact problem. I have only one form in my frm collection. The form in that collection differs depending on the situation (which is why it isn't a known form name, someone else wrote the original code). I'm trying to call a public function called "Update" which is in various forms (frmBulletDisplay is one example).

    frmBulletDisplay(for example) has

    Public Function Update ()
    (with a lot of code)

    and my other function defines
    Dim frm As Form
    If isFormOpen Then Set frm = Forms(Me.lbxForm).Form '(Depending on which form the user is wanting to display)
    frm.Update

    the last line is what is causing the problems where the error message says "Run-time error '2465': Application-defined or object-defined error".
    (Yes Me.lbxForm is really set to frmBulletDisplay in this case)...

    Watyer

  11. #11

Posting Permissions

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



Click Here to Expand Forum to Full Width