How to address the controls of a continuous (sub)form

P

Peter J. Veger

In the design the controls get names such as btnTest, txtName, etc; when the
form is opened, in general more than one set of those control is visible.
How should one select e.g. the second btnTest?

Peter J. Veger, Best, netherlands
 
D

Douglas J Steele

You can't really: while there are multiple occurrences on the form, they're
all treated as one.

I'm assuming you want to make a change such as change the caption, toggle
visibility or something like that. If you tried to disable, say, the second
btnTest, all btnTest will be disabled.
 
P

Peter J. Veger

In my case, I want to get (using VBA) the values of a number of text
controls (all of one name) in a (details) subform.
So this action is not at design time but at run time.
Peter J. Veger, Best, netherlands
 
A

Albert D.Kallal

If you reference any the controls, they simply return the values of the
current record.

So, if your code is running in the "main" form, you can go:

me.MySubFormContorl.LastName

It is not clear "which" record in the sub-form you need to ref, but the
values of the controls simply return he current record. If you need to work
with more then one record, or all the records, then you should use a
recordset, and not bother using controls. (this advice applies even when you
are use non sub-form, so this approach is for any form).

dim rstSubRecs as dao.recordset


set rstSubRecs = me.MySubFormContorl.Form.RecordSetClone

do while rstSubRecs.eof = false
....process one reocrd
rstSubRecs.MoveNext
loop
 
P

Peter J. Veger

The main form gives info on a Boat, the subform gives the set of Owners (of
type Person) of the boat.
There is one primary owner and zero or more secundary owners.
What actions on the boat are allowed, depends on the type of owner.

I do not use Macro's (only Modules) nor DAO (only ADO) and of course I can
query the set of owners using the id of the boat.
I just thought that it would be easy if I were to able to access the set of
owners (in general, the records visible in a continuous form) e.g. as a
collection or as an array, but I could not find a reference.
(I find help in Office deficient, help in Office 2003 almost unusable, I
still use older documentation.)

Peter J. Veger, Best, Netherlands
 
A

Albert D.Kallal

e.g. as a
collection or as an array, but I could not find a reference.

Well, what the heck is a ado recorset? Is not that the most useful
collection you have at your finger tips?

You can very well use the same code example I gave with a ado.recordset (the
forms recordset returned is dao, or ado depending on what context).

What kind of collection could possibility be better then a ADO recordset
that represents all the records, and all the fields of your sub-form?

Why force the programmers/develperors to learn a whole new set, or way of
addressing the sub-forms data when you can use a familiar, tried and true
recrodset?

dim rstSubRecs as ADODB.Recordset

set rstSubRecs = me.MySubFormContorl.Form.RecordSetClone

do while rstSubRecs.eof = false

So, the example code does with with ado if you please....
 
P

Peter J. Veger

OK, thank you.
I was under the false impresssion that the Form property "RecordsetClone"
always returns an DAO recordset.

Peter J. Veger, Best, Netherlands
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top