Assume text boxes named:
txtRedHex (for entering a hex value for red),
txtRedDec (for entering a decimal value for red),
txtGreenHex, etc.
and one named:
txtCombined (for entering a combined value (long)).
Private Sub txtCombined_AfterUpdate()
Dim btRed As Byte, btGreen As Byte, btBlue As Byte
Dim lngColor As Long
If IsNum(Me.txtCombined) Then
btRed = Me.txtCombined Mod 256
lngColor = Me.txtCombined \ 256
btGreen = lngColor Mod 256
btBlue = lngColor \ 256
Me.Section(acDetail).BackColor = Me.txtCombined
Me.txtRedDec = btRed
Me.txtGreenDec = btGreen
Me.txtBlueDec = btBlue
Me.txtRedHex = Hex(btRed)
Me.txtGreenHex = Hex(btGreen)
Me.txtBlueHex = Hex(btBlue)
Else
Beep
End If
End Sub
Set the After Update property of the other 6 boxes to:
=SetColor()
Function SetColor()
Dim ctl As Control
Set ctl = Screen.ActiveControl
Select Case ctl.Name
Case "txtRedDec"
Me.txtRedHex = Hex(ctl.Value)
Me.txtCombined = RGB(Me.txtRedDec, Me.txtGreenDec, Me.txtBlueDec)
Case "txtGreenDec"
Me.txtGreenHex = Hex(ctl.Value)
Me.txtCombined = RGB(Me.txtRedDec, Me.txtGreenDec, Me.txtBlueDec)
Case "txtBlueDec"
Me.txtBlueHex = Hex(ctl.Value)
Me.txtCombined = RGB(Me.txtRedDec, Me.txtGreenDec, Me.txtBlueDec)
Case "txtRedHex"
Me.txtRedDec = Val("&H" & ctl.Value)
Me.txtCombined = RGB(Me.txtRedDec, Me.txtGreenDec, Me.txtBlueDec)
Case "txtGreenHex"
Me.txtGreenDec = Val("&H" & ctl.Value)
Me.txtCombined = RGB(Me.txtRedDec, Me.txtGreenDec, Me.txtBlueDec)
Case "txtBlueHex"
Me.txtBlueDec = Val("&H" & ctl.Value)
Me.txtCombined = RGB(Me.txtRedDec, Me.txtGreenDec, Me.txtBlueDec)
Case "txtCombined"
Case Else
MsgBox "Active control " & ctl.Name & " not handled."
End Select
Me.Section(acDetail).BackColor = Me.txtCombined
End Function