L
Laurel
I got some great code from a site recommended by Al Campagna (see post
"Slide to Left" for specific URL if needed.) It allows me to interrupt the
print process and set part of the string to be printed to bold. My HUGE
problem is that after finding this wonderful code and getting my report all
set up, I find that the controls that this code acts on don't show up on the
printed page - that is the hardcopy, although they show up nicely on the
screen. Can anyone help?
' **START CODE
' Written by Stephen Lebans 1999
' (e-mail address removed)
' 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 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 txtFirstLine. 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
' =[Last Name]&", "&[First Name]
' 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 = "txtFirstLine") Or (CtlDetail.Name =
"txtSecondLine") Then
With CtlDetail
.Visible = False
intPosition = InStr(1, .Value, ",")
If intPosition = 0 Then
GoTo NextCTL
End If
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
If CtlDetail.Name = "txtSecondLine" Then
.CurrentY = 250
End If
' For some reason must be Me.Print not .Print
Me.Print strLast;
Me.Print ", ";
' Reset Font-> NO Bold for First Name
.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
NextCTL:
Next
' Cleanup
Set CtlDetail = Nothing
End Sub
"Slide to Left" for specific URL if needed.) It allows me to interrupt the
print process and set part of the string to be printed to bold. My HUGE
problem is that after finding this wonderful code and getting my report all
set up, I find that the controls that this code acts on don't show up on the
printed page - that is the hardcopy, although they show up nicely on the
screen. Can anyone help?
' **START CODE
' Written by Stephen Lebans 1999
' (e-mail address removed)
' 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 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 txtFirstLine. 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
' =[Last Name]&", "&[First Name]
' 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 = "txtFirstLine") Or (CtlDetail.Name =
"txtSecondLine") Then
With CtlDetail
.Visible = False
intPosition = InStr(1, .Value, ",")
If intPosition = 0 Then
GoTo NextCTL
End If
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
If CtlDetail.Name = "txtSecondLine" Then
.CurrentY = 250
End If
' For some reason must be Me.Print not .Print
Me.Print strLast;
Me.Print ", ";
' Reset Font-> NO Bold for First Name
.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
NextCTL:
Next
' Cleanup
Set CtlDetail = Nothing
End Sub