By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 2,763 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Object variable question

P: n/a
I need to have a way to identify the individual text and label controls on a
form within my VBA code in order to set the properties depending on
conditions. There are 25 text fields, and I don't want to repeat 25 loops of
code; I want to do it in one nice loop using a counter, stepping through
each control and setting the properties for each.

How do you identify the address to the controls? I've tried declaring as an
object type or control type, but I can't figure out how to store the address
of the particular control in it, so that I can reference it later to change
it's properties. The VB Help is hard to figure on this one.
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

P: n/a
Bruce Acciavatti wrote:
I need to have a way to identify the individual text and label controls on a
form within my VBA code in order to set the properties depending on
conditions. There are 25 text fields, and I don't want to repeat 25 loops of
code; I want to do it in one nice loop using a counter, stepping through
each control and setting the properties for each.

How do you identify the address to the controls? I've tried declaring as an
object type or control type, but I can't figure out how to store the address
of the particular control in it, so that I can reference it later to change
it's properties. The VB Help is hard to figure on this one.

For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox
Case acListBox
Case acComboBox
Case acCheckBox
Case acLabel
Case Else
MsgBox ctl.Name & " look my type up in help"
End Select
Next

For some odd reason Intellisys doen't recognize ctl.Name or
ctl.ControlType but this works find.

Some controls have different properties than others. You want to update
properties that exist for the type otherwise you need to do some error
checking.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.