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.
Re: Calling a forms Public routine
That should work as long as all forms have a public sub called ResizeForm.
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
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.
Re: Calling a forms Public routine
vb Code:
Private Sub Command1_Click()
Dim frm As Form
For Each frm In Forms
If frm.Visible = True Then frm.resizeform
Next frm
End Sub
works fine as long as each form has that particular function. Which from what you just said seems like each does :)
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.
Re: Calling a forms Public routine
Hell-Lord,
That was the first thing I tried... No Joy!!!
Re: Calling a forms Public routine
That is odd works fine for me...
Re: Calling a forms Public routine
Quote:
Originally Posted by Hell-Lord
vb Code:
Private Sub Command1_Click()
Dim frm As Form
For Each frm In Forms
If frm.Visible = True Then frm.resizeform
Next frm
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.
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
Re: Calling a forms Public routine
http://www.vbforums.com/attachment.p...id=47243&stc=1
I just wanted to point out that the thread you replied to is 2 years old so you may not get any response.