Change backcolor on account change (1 Viewer)

ClaraBarton

Registered User.
Local time
Today, 03:35
Joined
Oct 14, 2019
Messages
685
I have a form of Accounts with a subform of register. The subform is Parent/Child Account number.
I'd like to tie the register background color to the account color. I can't figure out which event to use.
Change of account triggers the Parent/Child connection.
So I tried the Current Event.
Placing a txtbox of the color on the parent form never triggers on change.
I tried including it in the date and account filters but that didn't work.

Code:
Private Sub Form_Current()
Dim frm As Form
Set frm = Me.Parent.Register.Form
    [SelectedID] = Me.AccountID
     frm.Detail.BackColor = DetailColor(Me.fColorID)
End Sub

Public Function DetailColor(ID As Long)
Dim bckColor As String
    Select Case ID
        Case 13
            bckColor = &H131313
        Case 14
            bckColor = &H5149E9
        Case 15
            bckColor = &H9E949A
        Case 16
            bckColor = &H7DFB37
        Case 17
            bckColor = &HFAFFF7
        Case 18
            bckColor = &HE583D9
        Case 19
            bckColor = &HF2F244
     End Select
End Function

1751565306223.png
 
No, it is an RGB value, long integer.
There are a few defined constants like vbYellow, but otherwise you need to cobble a color together yourself. There is a color selector for the color properties.
 
Add AS String to the first line

Actually, if you look at how the function is used, it should be declared "AS LONG" although I believe the default for a function of undeclared type is AS VARIANT and that might work via "LET Coercion" rules.
 
Actually, if you look at how the function is used, it should be declared "AS LONG" although I believe the default for a function of undeclared type is AS VARIANT and that might work via "LET Coercion" rules.
All I can say is that I added that and it worked.
I did not realise at that time what the type should be. I took it that the O/P knew that. :(

Though if the Type is Long for the colour, then I agree As Long would be better. In fact it still works with no AS at all.

1751617819240.png
 
Last edited:

Users who are viewing this thread

Back
Top Bottom