|
-
Aug 2nd, 2007, 01:18 AM
#1
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.
-
Aug 2nd, 2007, 01:31 AM
#2
Re: Calling a forms Public routine
That should work as long as all forms have a public sub called ResizeForm.
-
Aug 2nd, 2007, 01:33 AM
#3
Addicted Member
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
-
Aug 2nd, 2007, 01:36 AM
#4
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.
-
Aug 2nd, 2007, 01:39 AM
#5
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
-
Aug 2nd, 2007, 01:40 AM
#6
Addicted Member
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.
-
Aug 2nd, 2007, 01:41 AM
#7
Re: Calling a forms Public routine
Hell-Lord,
That was the first thing I tried... No Joy!!!
-
Aug 2nd, 2007, 01:44 AM
#8
Re: Calling a forms Public routine
That is odd works fine for me...
-
Aug 2nd, 2007, 01:52 AM
#9
Re: Calling a forms Public routine
 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.
-
Oct 23rd, 2009, 03:19 PM
#10
New Member
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
-
Oct 23rd, 2009, 04:02 PM
#11
Re: Calling a forms Public routine

I just wanted to point out that the thread you replied to is 2 years old so you may not get any response.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|