Control Array to clear values

G

Guest

Next ctlHi,

I need to write a control array that will loop through the textbox controls
on my form that have an index from 0 to 23 and set the value to "" or null.

The reason I need to refer to their tab index is that I cannot clear all of
the textboxes as I only want specifically those that are indexed from 0 to 23.

I am having difficulty finding the syntax. Any help would be much appreciated!

Sandy
 
J

John Vinson

Next ctlHi,

I need to write a control array that will loop through the textbox controls
on my form that have an index from 0 to 23 and set the value to "" or null.

The reason I need to refer to their tab index is that I cannot clear all of
the textboxes as I only want specifically those that are indexed from 0 to 23.

I am having difficulty finding the syntax. Any help would be much appreciated!

Sandy

One way I've done this is to use the Tag property of the form
controls. For instance, you could set the Tag property of each control
that you want cleared to "ClearMe" and use code like:

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "ClearMe" Then
ctl = Null
End If
Next ctl

I'd be rather leery of reusing the TabOrder property for this purpose;
it's got its other use and Access will renumber it very readily.

John W. Vinson[MVP]
 
G

Guest

Thank you for your reply John.

I have not used VBA to create a control array before, only VB6. In VB, I
would have used the index property, that is something you can change in the
properties.

Is it possible, without deleting and re-adding the controls in Access, to
re-order the indexes? I would rather loop through in reference to the control
index.

Thanks,

Sandy
 
G

Guest

The Tag worked great! Thank you!

Sandy

Sandy said:
Thank you for your reply John.

I have not used VBA to create a control array before, only VB6. In VB, I
would have used the index property, that is something you can change in the
properties.

Is it possible, without deleting and re-adding the controls in Access, to
re-order the indexes? I would rather loop through in reference to the control
index.

Thanks,

Sandy
 
L

Larry Linson

I have not used VBA to create a control array before, only VB6. In VB, I
would have used the index property, that is something you can change in
the
properties.

Well, there's one problem. In classic VB, you could create a Control Array,
but you cannot in Access. You could create an Array of Controls, or use the
Controls Collection of the Form, but the Control Array is a feature of the
Visual Basic product.
Is it possible, without deleting and re-adding
the controls in Access, to re-order the indexes?
I would rather loop through in reference to the
control index.

As there is no Control Array, there isn't an index to the Control Array. I
am not aware that you can control the index in the Controls Collection of
the Form. You could make the number part of the ControlName, e.g., Ctl0 -
Ctl23 and use the format

For i = 0 to 23
Forms!<yourformname>("Ctl" & i) = ...
Next i

to refer to them.

Larry Linson
Microsoft Access MVP
 

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