Can I get an explanation for why a form is acting a certain way?

  • Thread starter Thread starter Dennis Snelgrove
  • Start date Start date
D

Dennis Snelgrove

I've got a form (frmShiftVariables) where I've got textboxes holding a
number of values that I want kept for the duration of the session. The boxes
were able to be referenced with no problems until I changed the Form's "Has
Module" property to No. All of a sudden, I'm getting "Object Required"
errors whenever anything tries to reference the textboxes. As soon as I put
a module back on the form, it worked fine again. I know how to solve this,
but I don't understand *why* it happened. Can anyone explain the logic
underlying this?

Thanks...
 
Hi Dennis,

Are you using the 'dot' style of reference for controls? Though this is my
prefered method of referring to a control on a form, I think that this is
one of the caveats - I am pretty sure that it doesn't work if the form
doesn't have a class module. I'll test it when I have more time but you
might be able to do a quick test on your end to confirm this. In the dark
corners of my memory I seem to recall reading or encountering this.
 
Howdy Sandra!

Yes, I do use that style of control reference. So that's probably why this
is happening, huh? Well, so long as I know what's caused it...

Thanks for the explanation...

Sandra Daigle said:
Hi Dennis,

Are you using the 'dot' style of reference for controls? Though this is my
prefered method of referring to a control on a form, I think that this is
one of the caveats - I am pretty sure that it doesn't work if the form
doesn't have a class module. I'll test it when I have more time but you
might be able to do a quick test on your end to confirm this. In the dark
corners of my memory I seem to recall reading or encountering this.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Dennis said:
I've got a form (frmShiftVariables) where I've got textboxes holding
a number of values that I want kept for the duration of the session.
The boxes were able to be referenced with no problems until I changed
the Form's "Has Module" property to No. All of a sudden, I'm getting
"Object Required" errors whenever anything tries to reference the
textboxes. As soon as I put a module back on the form, it worked fine
again. I know how to solve this, but I don't understand *why* it
happened. Can anyone explain the logic underlying this?

Thanks...
 
Dennis said:
I've got a form (frmShiftVariables) where I've got textboxes holding a
number of values that I want kept for the duration of the session. The boxes
were able to be referenced with no problems until I changed the Form's "Has
Module" property to No. All of a sudden, I'm getting "Object Required"
errors whenever anything tries to reference the textboxes. As soon as I put
a module back on the form, it worked fine again. I know how to solve this,
but I don't understand *why* it happened. Can anyone explain the logic
underlying this?


That's happening because you're using a class type reference
like
Form_frmShiftVariables.textbox

But, a form by itself is not a class, it's the form's module
that is the class. So, when you remove the module, the
reference is to an undefined object.

You can eliminate all this confusion (and more that you
probably haven't seen yet) by using the standard kind of
reference through the Forms collection:

Forms!frmShiftVariables.textbox

which doesn't involve the form's class module.
 
It is possible you have some code that uses the following syntax:

form_YourFormName

You SHOULD NOT use the above format (unless you have to).

You should use:

forms!YourFormName

or

forms("YourFormName")

And, that first example is ONLY valid if a form has code in it. When you add
code to a form, them access makes a class object out of that form.

When you set the forms module property to "no", then you can't references
the form as class object, and ms-access does not create a object as above
that you can use in code. So, the first above example don't work on forms
that have no code.....

And, if for some reason you "have" to use the first example to ref a form,
then you MUST have at least some code in the form, and the forms module
property MUST be set to yes. By the way, the reason for that setting is to
enable you to create what is called a lightweight form that does NOT have a
code module, nor does ms-access has to create a class object out of the form
that you can reference (thus, you save ram/memory, and the form loads
faster). Of course, this feature goes back to when a good pc had 16 megs of
ram, and does not effect things much today with our super processing and
memory that we now have. On a good pc, you can't tell the difference in load
time between a lightweight form and a form with a module of code...
 
Back
Top