icweb
icweb

Reputation: 57

MS Access vba programmatically accessing and setting label properties

Is it possible to access labels programmatically with VBA. I'd like to create a number of labels using a for loop such as that shown below which would set all labels named "Label1" to "Label20" to visible

for a_counter = 1 to 20
Me.Label(a_counter).Visible = True
next a_counter

Is something such as the above possible?

Upvotes: 2

Views: 5560

Answers (2)

HansUp
HansUp

Reputation: 97101

You can refer to each of those label controls, "Label1" thru "Label20", by name from the form's Controls collection.

For a_counter = 1 To 20
    Me.Controls("Label" & a_counter).Visible = True
Next a_counter

Upvotes: 4

Philippe Grondier
Philippe Grondier

Reputation: 11138

labels are a specific kind of controls in access forms. You should be able to write down some code like this:

function listLabels()
dim m_ctl as control

for each m_ctl in screen.activeForm.controls
    if m_ctl.type = ....   'please check the control types available!
        debug.print m_ctl.name
    end if
next m_ctl

end function 

Be careful. I am not even sure of the control's properties (.type, .name) but you will easily find them in the help. Look for 'control' object.

Upvotes: 1

Related Questions