Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 formats in one Access text box???

Status
Not open for further replies.

sha76

Programmer
Sep 2, 2002
5,085
GB
Not sure that this one's even possible, but I've got a date field & need to change the format of just the day if certain criteria are met.

Thanks for any help with this

Sharon
 
Sharon,

It's probably possible, what are you looking to do? Kyle
 
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.

Sharon
 
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!

Thanks for helping,

Sharon
 
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.
 
Ok, when I said control, i meant data source.
 
Went for the unbound RTB & everything's now working juist the way I wanted - thank-you!

Sharon
 
If you are using Access 2k or XP then use conditional formatting. It can be applied to text boxes and works the same way it does in excel.

HTH

Ben ----------------------------------------
Ben O'Hara
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top