Identifying a control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I wish to scan through all controls on a form in order to identify a control
based on an autonumber field in a table. Any ideas would be appreciated
 
In the RecordsetClone of your form, examine the Type and Attributes of the
Field that your controls are bound to.

As you loop through the controls on your form, the first step is to skip
over the controls that have no Control Source property (such as lines,
labels, command buttons.) For those that have a ControlSource, you can skip
the ones that are unbound (Control Source is a zero-length string), or are
bound to an expression (starts with "=".) That leaves you with those bound
to a field.

You can find the details of that field by examining:
Me.RecordsetClone.Fields(Me.Text0.ControlSource)
It is an AutoNumber of its Type is dbLong, and its (Attributes And
dbAutoIncrField) is non-zero.

This link illustrates how to go about it:
Assign default values from the last record
at:
http://allenbrowne.com/ser-24.html
The code in that link eliminates the autonumbers (so as not to try to assign
a value to them), but the process of identifying them is the same.
 
Allen,

Access 2000 help files would never have revealed this secret:-

If (Rc(C.ControlSource).Attributes And dbAutoIncrField) > 0& then

Help file says of ATTRIBUTES .. "Sets or returns the attributes of files or
folders"

It works a treat - many thanks for your help.

Bernie
 
Great. Solved.

In doesn't matter for this case, but some of the system attributes are
negative, so I would prefer:
If (Rc(C.ControlSource).Attributes And dbAutoIncrField) <> 0& Then

And I agree that this kind of thing is not obvious.
 

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

Back
Top