Connecting Tech Pros Worldwide Forums | Help | Site Map

Mixing Formats within a textbox - revisited - Lebans

Newbie
 
Join Date: Mar 2007
Posts: 3
#1: Mar 24 '07
I am using Lebans lady example to mix Bold and Normal in a single line text box, I have altered it and I still cant get it to bold the text I need bolded I have pasted it here, can somebody help? I need Last_Name, Suff, First_Name, Middle_Name bolded, the rest normal. Thanks Melissa


' **START CODE
' Written by Stephen Lebans 1999
' Stephen@lebans.com
' www.lebans.com

' This sample database is for a Poster named "Lady".
' She wanted to print her concatenated Control with
' one part in Bold and the rest normal.

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

Const TWIPS = 1
Dim strLast_Name As String
Dim strSuff As String
Dim strFirst_Name As String
Dim strMiddle_Name As String
Dim strCompany As String
Dim strAddress_1 As String
Dim strCity As String
Dim strZip As String
Dim strWork_Phone As String
Dim strSpecialty_1 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



' 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 = "text3" Then
With CtlDetail
.Visible = False
intPosition = InStr(1, .Value, ",")
strLast_Name = Left(.Value, intPosition - 1)
strSuff = Mid(.Value, intPosition + 2)
strFirst_Name = Mid(.Value, intPosition + 2)
strMiddle_Name = Mid(.Value, intPosition + 2)
strCompany = Mid(.Value, intPosition + 2)
strAddress_1 = Mid(.Value, intPosition + 2)
strCity = Mid(.Value, intPosition + 2)
strZip = Mid(.Value, intPosition + 2)
strWork_Phone = Mid(.Value, intPosition + 2)
strSpecialty_1 = 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_Name;
Me.Print ", ";
Me.Print strSuff;
Me.Print ", ";
Me.Print strFirst_Name;
Me.Print ", ";
Me.Print strMiddle_Name;
Me.Print ", ";
' Reset Font-> NO Bold for FirstName
.FontBold = False
'.FontItalic = False
Me.Print strCompany;
Me.Print ", ";
Me.Print strAddress_1;
Me.Print ", ";
Me.Print strCity;
Me.Print ", ";
Me.Print strZip;
Me.Print ", ";
Me.Print strWork_Phone;
Me.Print ", ";
Me.Print strSpecialty_1;


' Restore Reports original Font settings
.ScaleMode = oldScaleMode
.FontBold = oldFontBold
.FontItalic = oldFontItalic
.FontName = oldFontName
.fontsize = oldfontsize
.ForeColor = oldForeColor

End With


End If
Next

' Cleanup
Set CtlDetail = Nothing
End Sub

nico5038's Avatar
Moderator
 
Join Date: Nov 2006
Location: The Netherlands
Posts: 2,232
#2: Mar 24 '07

re: Mixing Formats within a textbox - revisited - Lebans


The standard Access textbox won't support differences in bold/italics/etc.
Did you try the rich text control:
http://www.lebans.com/richtext.htm

Nic;o)
Newbie
 
Join Date: Mar 2007
Posts: 3
#3: Mar 26 '07

re: Mixing Formats within a textbox - revisited - Lebans


Yes the code I posted above IS from Lebans "Lady" example and works perfectly - however I have several concatenated fields and I need the first four bolded not just the first as in Lebans code - I messed around with it to see if I could get it to work but the best I could do caused all my fields to be bolded.
nico5038's Avatar
Moderator
 
Join Date: Nov 2006
Location: The Netherlands
Posts: 2,232
#4: Mar 26 '07

re: Mixing Formats within a textbox - revisited - Lebans


Quote:

Originally Posted by mdarling

Yes the code I posted above IS from Lebans "Lady" example and works perfectly - however I have several concatenated fields and I need the first four bolded not just the first as in Lebans code - I messed around with it to see if I could get it to work but the best I could do caused all my fields to be bolded.

Hmm, The line:

.FontBold = False

Should be the "border" between bold and not bold.
Just make sure that the control (textbox?) used is a copy of the working field and has the correct name.

Nic;o)
Newbie
 
Join Date: Mar 2007
Posts: 3
#5: Mar 26 '07

re: Mixing Formats within a textbox - revisited - Lebans


Thanks, I have checked what you suggestd and verified the name of my textbox. I think it has something to do with the placement of the fields themselves in this part of the code:

Expand|Select|Wrap|Line Numbers
  1.  With CtlDetail
  2.             .Visible = False
  3.             intPosition = InStr(1, .Value, ",")
  4.             strLast_Name = Left(.Value, intPosition - 1)
  5.             strSuff = Mid(.Value, intPosition + 2)
  6.             strFirst_Name = Mid(.Value, intPosition + 2)
  7.             strMiddle_Name = Mid(.Value, intPosition + 2)
  8.             strCompany = Mid(.Value, intPosition + 2)
  9.             strAddress_1 = Mid(.Value, intPosition + 2)
  10.             strCity = Mid(.Value, intPosition + 2)
  11.             strZip = Mid(.Value, intPosition + 2)
  12.             strWork_Phone = Mid(.Value, intPosition + 2)
  13.             strSpecialty_1 = Mid(.Value, intPosition + 2)
  14.  
  15.             'Debug.Print strLast
  16.             'Debug.Print strFirst
  17.  
  18.         End With
Should the mid values above be changed? I experimented with that but I just couldn't seem to get it right.
Reply


Similar Microsoft Access / VBA bytes