Reputation: 28069
How do I bold a certain word in the caption of a Microsoft Access label?
If it helps, the text itself is stored in a Microsoft Access table.
An example is below. I have a Microsoft Access form with a label, in the Form_Load()
event I set the caption property of this label to the value returned in a DLookup query like so:
Private Sub Form_Load()
Me.Label0.Caption = DLookup("Field1", "Table1", "[ID] = 1")
End Sub
My text is as follows:
The quick brown fox jumps over the lazy dog
I want to embolden the word Lazy. Is this possible? If so, how do I do this?
Thanks
Upvotes: 8
Views: 23591
Reputation: 91376
You do not mention the version of Access, for 2007 (AFAIK) and 2010, you can create a textbox and set the Text Format on the data tab to Rich Text. You can then set the Control Source to:
="The quick <b>brown</b> fox"
Change a few more properties, such as Locked and Enabled and you will have a textbox that looks and acts like a label.
Upvotes: 10
Reputation: 33175
How bad do you want this? Because I have a really crazy answer, but it might work.
Replace your label with a Web Browser Control, create a temporary html file, then point the Web Browser to that. You'll need to add a field to the underlying table (or at least I did) because the control has to be bound or you can't change the ControlSource - I think.
I put a Web Browser control on a form, turned scrollbars off, and generally tried to make it look like a label. I didn't have complete success with that, but maybe you're better at it than me.
I added a Text field to my table called "FakeLabel". The Web Browser control source should point to that field.
For purposes of testing, I put a commandbutton on the form with this code
Private Sub Command113_Click()
Dim sFile As String
Dim lFile As String
sFile = Environ("TEMP") & "\fakelabel.html"
lFile = FreeFile
Open sFile For Output As lFile
Write #lFile, "The <strong>quick</strong> brown fox jumped over the <em>lazy</em> dog"
Close lFile
Me.Recordset.Edit
Me.Recordset.Fields("FakeLabel").Value = sFile
Me.Recordset.Update
Me.WebBrowser112.Requery
End Sub
Here's what it looks like after I click the button. If you can get rid of that top padding, it could really look like a label.
Upvotes: 3