tcb said:
Older versions of Access allowed you to build expressions in code as
you can in controls.
For example you could build something like this to refer to a subform:
Me.sfCustomerConcern.Form.Controls
New versions don't have that build feature (though it is available
through third party).
Hum, not sure what you mean by "build" feature. the above expression you
have should have worked find for that last 5 versions of access (that going
back to office 95, which is more then 10 years old now. So, I don't see any
problem with the above expression. And, inteli-sense (auto completion)
should work for the above.
What is the best way to build such expressions or statements in code?
Well, if you always compile your code after you make changes, then as you
type new code, then inteli-sense will work. In the above, you would type in
me.
And then you should get a popup list.
If you are not getting a popup list, then likely your code has "many" or
some compile errors in other locations. do a debug->compile, and fix all of
the existing errors. When you got all errors fixed, THEN inti-sense, and
autocompltion should work as you type new code.
So, I can't think of anything that changed in the last 5 versions in terms
of the above expression. It should be business as usual.
I know that:
Form_sfCustomerConcern.Controls refers to the same subform named above.
NO NO, you do you NOT want to use the above format to reference forms. That
syntax of
Form_YourFormName
Refers to the BASE class object. If you form is NOT loaded, and you use the
above, such as:
msgbox form_YourFormName!LastName
The above code will actually cause the form to load (if it not yet loaded).
And, this means all of the startup events (on-open, on-load etc) will run.
This is certainly NOT the behavior one would expect with the above
expression. You loose complete control of when the form loads, and the
startup events fire.
Further, by using the above syntax, then the form does NOT get added to the
forms collection (at least the key "name" as a string does not).
So, the syntax to reference a form is:
me (this must be used inside of a forms module, and "me" is the
current form instance)
forms!YourFormName
forms("YourFormName")
note how the last one is a string:
strForm = inputbox("what form to load")
docmd.OpenForm strForm
msgbox "last name is " & forms(strForm)!LastName
Note how I can use a string var to ref the form. And, if you use the
form_yourforname syntax, the above code will break, and not work.
It is important to thus realize that you do NOT want to use the forms base
class object of
form_YourFormName
In fact, if you don't have any code in the form, then the form's base class
object is NOT created. This actually means that the syntax of
form_YourFormNaem
Will NOT WORK unless the form actually has some code in it (again, that is
enough reason to NOT use the above syntax, since it will NOT work if the
form ahs no code!!!.). Further, as mentioned, if you got multiple instances
of the form open, you can't tell which one. Worse, the above format can
cause a form to load if it is NOT already loaded (this is unexpected).
Further, it does not add the form to the forms collection correctly. So, all
in all, you REALLY want to avoid using the above syntax.
Can names of objects be inserted from the object browser into VB code?
As mentioned, any form with code becomes a base class object and you can
view it in the object browser. However, if the form has no code, then a base
class object NOT created.
Anway, I not sure whats changed in the last few versions, but you do want to
compile your code frequently (I do it after EVERY single time I change
code).
Furhter, if you don't comple your code in the currnet window and save it,
then next time ms-access will "load" the code module when you go back to
code, and this can be quite annoying. So, if you compile the code, then
ms-access thinks your are done, and thus does NOT load a zillon code modules
when you go back to the code window. the add bonus of this is that you need
to do this to ensure that inti-sense (auto completion) works also.