Search code examples
ms-accessvbabackcolor

VBA To Change BackColor Of Rectangle - Access


So I'm trying to change the backcolor of a rectangle within Access. I know you can easily do this Box1.BackColor = RGB(0, 0, 0), however I want to enter a value into a textbox and then display that color value as soon as you update the textbox.

I thought the following would work, but it doesn't.

Textbox1 = 0, 0, 0

Dim P1 as String
P1 = "RGB(" + Textbox1.text + ")"
Box1.Backcolor = P1

How can I go about changing the backcolor on the fly?


Solution

  • You could split the text, run the entries though int and feed it to RGB:

    Dim A As Variant
    A = Split(Textbox1.text,",")
    Box1.BackColor = RGB(Int(A(0)),Int(A(1)), Int(A(2)))