-
I am designing an app with multiple forms. I havn't found any good documentation as to how to communicate between forms. My current need is this: I have one form with a button that loads another form. This second form has an OK & a Cancel button on it. I need to know in the parent form which button was clicked. I could set a global variable in form2 but I'm hoping there is a cleaner way of doing this.
-
If that form only has an OK and a cancel button, consider using a message box instead. That will do what you want.
-
Theres a couple of other things you can try:
Hopefully you don't wantthe user to go back to the first form when the second one is open
1) You can have a private variable in the second form that is set when you click either ok or cancel. Then you can just hide the form and test the value in the original form. ie:
within form1:
form2.show vbmodal
the_result = form2.the_private_variable
bla bla
2) Create a class that opens the second form when some method is called. The "display" method can get the result (similarly to above) and then return it as it's return value. This way jsut "wraps" it up a bit more and makes it a bit neater i suppose. Although there a most likely processing overheads doing it this way.
HTH
Mark
-
Similar to what funkyd77 said:
Form1 event:
Form2.Show 1
MsgBox Form1.Tag
Form2 event:
Form1.Tag = "Hi!"
Unload Me