Solved Modify backcolor of a text field (1 Viewer)

boerbende

Ben
Local time
Today, 12:11
Joined
Feb 10, 2013
Messages
339
Dear readers

How can I modify textfield.backcolor via a function?

I use

Public Function ChangeColorDropDown(Variable As Variant, Backcolor As Long, Forecolor As Long)
If IsNull(Variable) Then
Backcolor = vbRed
Forecolor = vbWhite
Else
Backcolor = vbWhite
Forecolor = vbBlack
End If
End Function

Private sub dropdown1_afterupdate()
ChangeColorDropDown me.dropdown1, me.dropdown1.backcolor, me.dropdown1.forecolor
end sub

The colors are however not modified. What do I do wrong?

Many thanks

Ben
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:11
Joined
May 7, 2009
Messages
19,247
Code:
Public Function ChangeColorDropDown(Variable As Control, Backcolor As Long, Forecolor As Long)
If IsNull(Variable) Then
Variable.Backcolor = Backcolor
Variable.Forecolor = Forecolor
Else
Variable.Backcolor = vbWhite
Variable.Forecolor = vbBlack
End If
End Function

Private sub dropdown1_afterupdate()
ChangeColorDropDown me.dropdown1, vbred, vbwhite
end sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:11
Joined
Feb 28, 2001
Messages
27,194
Just as a side note: You defined a function but in fact this could have been a Sub. You are returning no value. Your call to activate the function would work equally well for Sub or Function because you weren't checking for any returned value. To avoid confusion in the future, may I suggest that you change the function to a sub?
 

Users who are viewing this thread

Top Bottom