If I have a checkbox on one form, and I want to access it's value on another form, what do I do? Any held would be great. Thanks.
Printable View
If I have a checkbox on one form, and I want to access it's value on another form, what do I do? Any held would be great. Thanks.
From Form2
VB Code:
Form1.Checkbox1.Value
mepaco's code is right.
I usually have a couple forms at least on most of my apps.
Am always sending data back and forth between them.
Only thing you have to watch out for is making sure any changes are reflected in linked forms.
I usually end up with
if frmMain.checkbox1.value = 1 then
msgbox "You have checked on the main form.",vbokonly
else
msgbox "You do not have checked on the main form.",vbokonly
end if
this would check to see if the main form was checked, could place it in any form.
Also can call functions from any form like this.
'GetDir function grabs the apps path.
strPath = fmMain.GetDir
then u save coding by only needing the fuction in one form.
I'm guessing since this is a checkbox you won't have to work with it much but if you did then you could always set a reference to it and make it easier to work with, and more efficient I believe.
VB Code:
Dim checkbox1 As CheckBox Set checkbox1 = Form1.checkbox1 If checkbox1.Value Then 'This is the checkbox on Form1 checkbox1.Enabled = False End If
If you set a reference to it like this then you can work with it just like it was a local control.