VBA formatting doesn’t work on first record but does on others

Big Pat

Registered User.
Local time
Today, 05:05
Joined
Sep 29, 2004
Messages
555
I’m trying to format a control on a continuous subform based on the value of another control on that same subform.

Main form”frm01Study” has several subforms, one of which is “frm03SpecialtyAdoptions” in continuous view. Two of the controls on this subform are AdoptedSpecialty (a text box) and PrimarySpecialty (a Yes/No checkbox with Visible property set to No)

On this form the users do not interact with this subform at all (they just view it), input being done via a different front-end. Anyway, if the hidden box is checked I want the textbox to appear in bold black font, otherwise in normal grey font. This is what I came up with
Code:
Private Sub Detail_Paint()
If Me.PrimarySpecialty.Value = True Then
    Me.AdoptedSpecialty.ForeColor = 0           'Black
    Me.AdoptedSpecialty.FontWeight = 700        'Bold
Else
    Me.AdoptedSpecialty.ForeColor = 12632256    'Grey
    Me.AdoptedSpecialty.FontWeight = 400        'Normal
End If
End Sub

But when I open the form, the first record just takes the default setting from the property sheet, although all subsequent records are displayed properly. I have tried the same code in the OnOpen, OnLoad and OnCurrent events of the subform, but I can’t get it to work reliably. Is there another step I need to do?

Thanks,
Pat
 
Form current would be the right procedure to use here.. As it will be triggered for every record.. Even the first one.. So where do you currently call this procedure from??
 
You do realise that in Continuous Forms such a procedure will alter the properties of the control for every record? The value of PrimarySpecialty in the current record will change all instances of AdoptedSpecialty.

The only way to successfully format Continuous Forms is with the Conditional Formatting.
 
Hi Galaxiom,

No I didn't realise that. One of the huge numbers of things I guess I don't realise about Access.

Well thanks for saving me from wasting any more time on this. I'll have a go at the conditional formatting approach.

Pat
 
Oh good grief ...it was that easy! I can't believe I spent hours yesterday trying to figure that out.

Sometimes the most intelligent approach is knowing the right person to ask!!!

Thanks again :D
 

Users who are viewing this thread

Back
Top Bottom