How to pass values between forms?

brianjessup

Registered User.
Local time
Yesterday, 17:24
Joined
May 25, 2003
Messages
36
How do you pass a value in a module in the mainform to a subform? I have a timer running in the mainform that saves the current time in milliseconds into the variable "tempTime". When a user presses a command button on the subform, I'd like the time to be stored in a txtbox, so the subform has to get access to the tempTime variable on the mainform. The only way I can think to do it, is to have a hidden label constantly updated with the time on the subform by the code on the mainform and then grab the data from that.

Thanks!
Brian
 
Hi,
If you declare the variable as a Public variable in your main form it will then be available as a property of the main form.
I.e. A Form is an instance of a class, Public variables within classes are treated as properties.
So if you have a public variable called myVar in your main form, you should be able to access the data in it via your subform by referencing MainForm.myVar

HTH,
Patrick
 
But then...

Wow, great answer, that worked very well. But is there a way to control a subform's variable value from the mainform? I'd like a mainform subroutine to tell the subform that a variable should be set to 1.
 
Hi,
It works both ways - you can declare a Public variable in your subform & reference it from your main form in the same manner.
(YourSubForm.YourVar)

Regards,
Patrick
 

Users who are viewing this thread

Back
Top Bottom