Using VBA: Assigning a Value to Control a Label on a Custom Form

I am working in VBA code behind a custom form. I have a string variable named block that matches the name of a text label in my custom form. Considering other questions, it seems that using the control function gives you the ability to control the label settings in a custom form. The block variable is a string of name labels.I get an error on all attempts below

 Me.Controls(block).BackColor = &HFFFF&

      

When I try hard code to make sure it is the exact name of the label, I still get the error

 Me.Controls("S111").BackColor = &HFFFF&

      

The following line works:

 Me.S111.BackColor = &HFFFF&

      

When I try to use a similar method, I get another error:

Me.block.BackColor = &HFFFF&

      

What am I doing wrong and what am I making possible?

+3


source to share


1 answer


The control Me.S111

is an object.



Dim objObject as Object '(Not type String)
Set objObject = Me.S111
objObject.BackColor = &HFFFF&

      

+1


source







All Articles