A simply developpement question

  • Thread starter Thread starter bart6285
  • Start date Start date
B

bart6285

Hi everybody,

I've got a simply question in vba developpement.
I don't remember how can i reference a collection variable forms to a
form that contain a subform. I need to do this to navigate all the
objects that contains in the subforms.

By example i've got,

frm as forms
ctl as control

i try this in my function, strFormName and strSubFormName are string
variable parameter of my function

set frm = Forms(strFormName).strSubFormName.Form.Name

For each ctl in frm.controls

next

Can anyone help me with this,

Thanks very much to you!
 
For Each ctl in Forms(strFormName).Controls(strSubFormName).Form.Controls
<whatever you want to do here>
Next
 
1) Double check your use of plurals (a collection) vs. a single member of
that collection:
"frm as forms" should be "frm as form", but that could easily be a typo in
the posting

2) Referencing the form in a subform control:
(re-read the above carefully: referencing the *Form property* of the
*control* that *contains* the subform is what returns the subform.

set frm = MyForm.MySubformContainer.Form
Or, for your purposes:
set frm = Forms(strFormName).Controls(strSubFormCONTROLName).Form

Note: *NOT* Form.Name, that will return a string that you can't do anything
with. You want the object itself.

Once you do that, "For each ctl in frm.Controls" should work fine.

When you add a subform, Access gives the same name to the container control
as the subform's name
(or to the same thing as the Caption property of the form, if one has been
set). I find this terribly confusing
(and misleading to novices for this very reason). I strongly suggest
renaming such controls immediately,
if for no other reason but to emphasize in your own mind that they are
different objects with different names.
I use a simple "sctl" prefix. This way I end up with a subform named
MySubform that appears in a control named sctlMySubform.
So, from the parent form:

Set frm = Me.sctlMySubform.Form
will set frm to MySubform

Hope this helps,
 
Thanks George for your Help, it was very helpful.

About the 'Junk' in return address. How can i delete it ?



Thanks agai
 
Back
Top