I've got a weird one, and am completely at a loss as to what to think of it.
I have a form with two subforms, and app-wide public variables to refer to all the attendant machinery – form, subform containers and subforms:
Code:
Public FD As Form_Data, FD_DSC_F As Form_DataDS, FD_EC_F As Form_DataEdit, CP_FD As AccessObject
Public FD_DSC As control, FD_EC As control
FD is the main form, FD_EC and FD_DSC are the subform containers, and FD_DSC_F and FD_EC_F are the subforms.
On startup, the variables are populated:
Code:
Set FD = Form_Data ' Main form
Set FD_DSC = FD.DataDS ' Datasheet subform control
Set FD_DSC_F = FD_DSC.Form ' Datasheet subform within control
Set FD_EC = FD.DataEdit ' Edit subform control
Set FD_EC_F = FD_EC.Form ' Edit subform within control
The subforms contain public variables that I use to indicate status – mdl_ is my personal coding style to indicate module-level public variables:
Code:
Public mdl_eDf_NovyZaznam As Boolean
Public mdl_eDf_UpravujemeZaznam As Boolean
Public mdl_eDf_NeulozeneZmeny As Boolean
Public mdl_eDf_LzeUlozit As Boolean
Public mdl_eDf_DruhChanged As Boolean
Public mdl_eDf_OblastChanged As Boolean
Public mdl_eDf_ChUVChanged As Boolean
I started getting some unexpected results, and traced it down to the fact that references to these module-level public variables are different depending on how I refer to them, and seemingly, the form variables do not fully reference the form to which they are supposed to point. For instance, the code:
seems to work, since executing this in break mode:
does in fact return true. However, the code:
Code:
Set FD_EC_F = FD_EC.Form
seems to me should set a pointer to the form, but executing this in break mode:
Code:
?fd_ec_f is form_dataedit
returns false. When I manually make visible changes to the form in break mode, using either method gives me the same results. For instance, both of the following turn the subform's background black:
Code:
fd_ec_f.section(0).backcolor=0
form_dataedit.Section(0).BackColor=0
However, here is a copy from the immediate window in break mode:
Code:
?Form_dataedit.mdl_eDf_UpravujemeZaznam
True
?FD_EC_F.mdl_eDf_UpravujemeZaznam
False
This should be referring to the exact same public variable in the form's code module, and the two methods clearly refer to the same form, since both of them have the same visible effects on the form's displayed properties. But referring to these public variables of that same form gives different results. In fact, manually executing these two statements in break mode:
Code:
fd_ec_f.mdl_eDf_UpravujemeZaznam = True
form_dataedit.mdl_eDf_UpravujemeZaznam = False
results in each 'version' of the variable getting set, and subsequent examination of 'each' variable shows the value that was last written to it, independent of the other.
How can this be? I found no mention of such behavior anywhere, except one blurb stating that the preferred way of doing this is by using property Get and Let functions, rather than public variables, that such variable are considered sub-standard coding practice. No explanation of why, though, and no indication that such constructs should not function properly.
Forms are class instances, and classes very specifically DO allow public variables. Can anyone enlighten me on what is going on here, before I go jump off the roof?