Change BackColor of Control

G

Gina

Hi all.

posted it already in modulescoding but pressed some button in OE and now the
'modulescoding ' does not seem to be active anymore...

sorry guys ..... I cannot find a way to get it 'bold' again ....

here's my problem ...

I would like to change the background when a control is locked
Running my code, I get is a message that an object is required !! ??

tried various ways but failed .... each time :-(

this is my code:

*****
Private Function Turn_Color(ctl As Control, OnOff As Boolean)
Dim obControlToSet As Object
Dim test

Set obControlToSet = ctl
test = obControlToSet.Name

If OnOff = False Then
test.BackColor = 16777215 ' here I get the message
Else
test.BackColor = 10040115 ' here I get the message
End If

obControlToSet = Nothing

End Function

***

Thanks,
Gina
 
D

Douglas J Steele

You're setting test to the name of the control that was passed, and then
trying to work on the name, not the control. All you should need is:

Private Function Turn_Color(ctl As Control, OnOff As Boolean)

If OnOff = False Then
ctl.BackColor = 16777215
Else
ctl.BackColor = 10040115
End If

End Function

You might also consider putting in code to check what type of control was
passed (since not all controls have a BackColor property):

Private Function Turn_Color(ctl As Control, OnOff As Boolean)

If TypeOf ctl Is TextBox Then
If OnOff = False Then
ctl.BackColor = 16777215
Else
ctl.BackColor = 10040115
End If
End If

End Function
 
G

Gina

Thanks Douglas,

I was messing around with it not seeing the most obvious.....
oh dear ;-|


I do the check what type of control in a function earlier as I have to check
some tags as well

thanks again :)

Gina
 
Top