does anyone know how to call sub from another form?
for example, i am working with form 1, but i need to call a command1_click() from form2, does anyone know how to do this?
-emptywords
Printable View
does anyone know how to call sub from another form?
for example, i am working with form 1, but i need to call a command1_click() from form2, does anyone know how to do this?
-emptywords
Dead easy.
There are 2 ways to do this...
Change the Command1_Click Event to Public instead of Private. Then in Form2 use...
Or, you could dump all the code from that event into a public sub inside a module, then you can call that code from any form you like.Code:Call Form1.Command1_Click
The second way is safer, but make sure it doesnt throw any of your variables out of scope.
You could also set it's Value property to True, which will also call the Command1_Click event.
Code:Form2.Command1.Value = True
Matthew, yeah but why do it the easy way when you can risk throwing all kinds of bugs into the program with my method! :)
ps. Won't your way force a refresh of the button's graphical DC clipping region?
Is that a particular problem?
Not all controls have a Value property. Also, What if the sub being accessed was not an sub linked to an object?Quote:
Originally posted by Matthew Gates
You could also set it's Value property to True, which will also call the Command1_Click event.
Only talkin' about a Command Button here :rolleyes:.