I've got a basic form based on a query. If the value in one field = 1 then I'd like to change the colour of the day in a date field (dd/mm/yyyy).
I've put some code in the form's On Current event which changes the whole field's format, but got stuck trying to do just the day.
Thanks, the rich text box definitely seems to be the solution. I've never used one before though & can't seem to get the code working!
I started out adapting some code from the MS site:
Private Sub Form_Current()
Dim BirthDay As String, BirthNotDay As String
'[dob] is the control source for the rich text box
BirthDay = Left([dob], 2)
BirthNotDay = Right([dob], 8)
With ActiveXCtldob
.SelBold = True
.SelText = BirthDay
.SelBold = False
.SelText = BirthNotDay
End With
this didn't appear to be selecting any text so I swapped .SelText for
.SelStart = 0
.SelLength = 2
and I've messed around with the order of the statements, but whatever I do I end up with it all bold or all normal!
I didn't know much about it either, (it's disabled at work, boo hoo), but I thought it would do the trick. Just had a mess around:
Private Sub UserForm_Activate()
rtb.Text = CStr(Date)
With rtb
.SelStart = 0
.SelLength = 2
.SelBold = 1
.SelLength = 0
End With
End Sub
Works fine setting the day to bold on an unbound RTB.
I get the feeling that it is the control source causing the problem. If the control source is incapable of richtext, then I would think that the bound control would also be incapable. Try changing the control source type, failing that, have the bound text box hidden with an on_change event linking it to an unbound richtextbox.
Rather than just waffle, I've tried it in Access.
The controls are basically the problem. I used a date type control and a memo control. Date type simply refused to update the record as the RTB is incompatible with the date control. The memo control cannot handle rich text and therefore converts it all to bold when updated. On first show, it worked fine, and was then all bold.
Two options then:
Use a directly bound field, but unbold everything before you update the datasource.
Or use an unbound RTB and update that from an invisible bound textbox.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.