dawn Master Poster
![](images/avatars/9310529940f56c812f39e.gif)
Joined: 26 Jun 2004 Posts: 311 Location: Mishawaka, IN
|
Posted: Fri Oct 17, 2008 1:09 pm Post subject: Make selected parts of a concatenated Control Bold or Italic |
|
|
Make selected parts of a concatenated Control Bold or Italic. Or can I make the first part of a string Bold and the rest normal.
QUESTION:
Is there a way to bold just part of a concatenated field.
Ex: =[LastName]&", "&[FirstName]
Could this be done and have the [LastName] ONLY bolded in a report???
ANSWER:
Code: |
' **START CODE
' Written by Stephen Lebans 1999
' macarthu@nbnet.nb.ca
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Const TWIPS = 1
Dim strFirst As String
Dim strLast As String
Dim intPosition As Integer
Dim CtlDetail As Control
Dim intMargin As Integer
' I'll leave in Italic and Color
' in case you want to use these
Dim oldFontBold As Integer
Dim oldFontItalic As Integer
Dim oldForeColor As Long
Dim oldFontName As String
Dim oldfontsize As Integer
Dim oldScaleMode As Integer
'Save current Font settings
With Me
oldFontItalic = .FontItalic
oldFontBold = .FontBold
oldForeColor = .ForeColor
oldFontName = .FontName
oldfontsize = .fontsize
oldScaleMode = .ScaleMode
End With
' Set Margin for Border we will draw
' around your concatenated control.
intMargin = 60
' Remember for this sample I am
' naming your control tblady. You MUST
' change the name here to match that of the actual control. Also
' I assumed the control source is exactly as you posted to the NG
' =[LastName]&", "&[FirstName]
' OK lets find your control and seperate
' the concatenated field.
' for each control in details control
For Each CtlDetail In Me.Section(acDetail).Controls
If CtlDetail.name = "tbLady" Then
With CtlDetail
.Visible = False
intPosition = InStr(1, .Value, ",")
strLast = Left(.Value, intPosition - 1)
strFirst = Mid(.Value, intPosition + 2)
Debug.Print strLast
Debug.Print strFirst
End With
With Me
' Make sure we are in Twips
.ScaleMode = TWIPS
' Grab Controls current Font settings
.FontName = CtlDetail.FontName
.fontsize = CtlDetail.fontsize
' Create desired Font settings
' for the Last Name - Bold Text
.FontBold = True
'.FontItalic = True
'.ForeColor = RGB(255, 0, 0) 'RED
.CurrentX = CtlDetail.Left
.CurrentY = CtlDetail.Top
' For some reason must be Me.Print not .Print
Me.Print strLast;
Me.Print ", ";
' Reset Font-> NO Bold for FirstName
.FontBold = False
'.FontItalic = False
Me.Print strFirst
' Restore Reports original Font settings
.ScaleMode = oldScaleMode
.FontBold = oldFontBold
.FontItalic = oldFontItalic
.FontName = oldFontName
.fontsize = oldfontsize
.ForeColor = oldForeColor
End With
With CtlDetail
'While we are here lets draw a box around each field
Me.Line ((.Left - intMargin), (.Top - intMargin))-Step((.Width
+ (intMargin * 2)), (.Height + (intMargin * 2))), 0, B
End With
End If
Next
' Cleanup
Set CtlDetail = Nothing
End Sub
' **END CODE |
|
|