Data Reports - Changing Font/Bold at runtime

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

Is is possible to change the font size and bold attribute of a data
report/access report during run-time?

I can't seem to get it to work. The following code does not throw an error
but has no effect on the report outcome.

Thanks for any help with this!

'If the word OPTION appears in the description, bold and resize the font and
maybe change the forecolor
Private Sub myDescription_Format(ByVal DataValue As StdFormat.StdDataValue)
If InStr(1, DataValue.Value, "OPTION") Then

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.Bo
ld = True

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").ForeCol
or = vbRed

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.Si
ze = 24

End If
End Sub
 
Jay said:
Is is possible to change the font size and bold attribute of a data
report/access report during run-time?

I can't seem to get it to work. The following code does not throw an error
but has no effect on the report outcome.

Thanks for any help with this!

'If the word OPTION appears in the description, bold and resize the font and
maybe change the forecolor
Private Sub myDescription_Format(ByVal DataValue As StdFormat.StdDataValue)
If InStr(1, DataValue.Value, "OPTION") Then

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.Bo
ld = True

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").ForeCol
or = vbRed

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.Si
ze = 24

End If
End Sub


I'm not even convinced that this is VBA code. What variable
type is StdFormat.StdDataValue? Even if that's some legal
construct that I've never seen before, this code would be so
far out of context as to make it incomprehensible.

I don't see anything that would invoke that procedure. It
sort of looks like you expect it to be called automatically,
is this somehow part of a class module that is sinking the
section's Format event? Maybe you are calling this
procedure from some other event procedure??

Access reports automatically invoke each **section's**
Format event only when the section's OnFormat property
contains [Event Procedure]. It seems as if you expect that
to happen for an individual control, but that's not how it
works.

The next misconception I see is that you are trying to
assing the ForeColor to an entire collection of controls in
one statement. That won't work either, you have to assign
the property to each control in the collection.

To make matters even more difficult, there is a gotcha when
using a section's Controls collection. It doesn't work on
Windows NT and XP systems - BUMMER!

Here's some AIR CODE that should do what I think you want:

Private Sub Detail_Format( . . .
Dim ctl As Control

If InStr(1, somecontrol.Value, "OPTION") Then
For Each ctl In Me.Controls
If ctl.Section = 0 Then 'only detail section
If ctl.ControlType = acTextbox _
Or ctl.ControlType = acLabel _
Then ' only text boxes and labels
Me.txtDescription.FontBold = True
Me.txtDescription.ForeColor = vbRed
Me.txtDescription.FontSize = 24
Else
Me.txtDescription.FontBold = False
Me.txtDescription.ForeColor = vbBlack
Me.txtDescription.FontSize = 12
End If
End If
Next ctl
End If
 
Thank You for your response. The reason for the unfamiliarity by you is
that this is code behind a Visual Basic Data Report not ACCESS per sey.
Here is the entire code. The only reason that I posted it here is because I
couldn't find a data reports news group. Maybe you could point me to one?

I don't have an event called Detail_Format like you mentioned (that is
ACCESS reports only). I don't believe that the code that you provided would
work for me.

The withevents that I declared caused these events show up in the drop down
events list.

Thank You for any input on this matter. It is important to my client!

Jay

Option Explicit

Dim WithEvents myStdData As StdDataFormat
Dim WithEvents myDescData As StdDataFormat
Dim WithEvents myDescription As StdDataFormat

Private Sub DataReport_Initialize()
Set myStdData = New StdDataFormat
Set myDescData = New StdDataFormat
Set myDescription = New StdDataFormat

Set
Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtSubOrder").DataFormat
= myStdData
Set Me.Sections("cmdEstimateNew_Header").Controls("txtOptionI").DataFormat
= myDescData
Set
Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").DataFor
mat = myDescription
End Sub

Private Sub myStdData_Format(ByVal DataValue As StdFormat.StdDataValue)
If DataValue.Value = "0" Then
DataValue = ""
End If
End Sub

Private Sub myDescData_Format(ByVal DataValue As StdFormat.StdDataValue)
If DataValue.Value = 0 Then
DataValue.Value = "True"
End If
End Sub
Private Sub myDescription_Format(ByVal DataValue As StdFormat.StdDataValue)
If InStr(1, DataValue.Value, "OPTION") Then

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.Bo
ld = True

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").ForeCol
or = vbRed
End If
End Sub

Marshall Barton said:
Jay said:
Is is possible to change the font size and bold attribute of a data
report/access report during run-time?

I can't seem to get it to work. The following code does not throw an error
but has no effect on the report outcome.

Thanks for any help with this!

'If the word OPTION appears in the description, bold and resize the font and
maybe change the forecolor
Private Sub myDescription_Format(ByVal DataValue As StdFormat.StdDataValue)
If InStr(1, DataValue.Value, "OPTION") Then

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.B
o
ld = True

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").ForeCo
l
or = vbRed

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.S
i
ze = 24

End If
End Sub


I'm not even convinced that this is VBA code. What variable
type is StdFormat.StdDataValue? Even if that's some legal
construct that I've never seen before, this code would be so
far out of context as to make it incomprehensible.

I don't see anything that would invoke that procedure. It
sort of looks like you expect it to be called automatically,
is this somehow part of a class module that is sinking the
section's Format event? Maybe you are calling this
procedure from some other event procedure??

Access reports automatically invoke each **section's**
Format event only when the section's OnFormat property
contains [Event Procedure]. It seems as if you expect that
to happen for an individual control, but that's not how it
works.

The next misconception I see is that you are trying to
assing the ForeColor to an entire collection of controls in
one statement. That won't work either, you have to assign
the property to each control in the collection.

To make matters even more difficult, there is a gotcha when
using a section's Controls collection. It doesn't work on
Windows NT and XP systems - BUMMER!

Here's some AIR CODE that should do what I think you want:

Private Sub Detail_Format( . . .
Dim ctl As Control

If InStr(1, somecontrol.Value, "OPTION") Then
For Each ctl In Me.Controls
If ctl.Section = 0 Then 'only detail section
If ctl.ControlType = acTextbox _
Or ctl.ControlType = acLabel _
Then ' only text boxes and labels
Me.txtDescription.FontBold = True
Me.txtDescription.ForeColor = vbRed
Me.txtDescription.FontSize = 24
Else
Me.txtDescription.FontBold = False
Me.txtDescription.ForeColor = vbBlack
Me.txtDescription.FontSize = 12
End If
End If
Next ctl
End If
 
Also the strange part is that this code does not throw an error at run-time
(if the code were wrong). There is just no effect on the report.

Thanks.
Marshall Barton said:
Jay said:
Is is possible to change the font size and bold attribute of a data
report/access report during run-time?

I can't seem to get it to work. The following code does not throw an error
but has no effect on the report outcome.

Thanks for any help with this!

'If the word OPTION appears in the description, bold and resize the font and
maybe change the forecolor
Private Sub myDescription_Format(ByVal DataValue As StdFormat.StdDataValue)
If InStr(1, DataValue.Value, "OPTION") Then

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.B
o
ld = True

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").ForeCo
l
or = vbRed

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.S
i
ze = 24

End If
End Sub


I'm not even convinced that this is VBA code. What variable
type is StdFormat.StdDataValue? Even if that's some legal
construct that I've never seen before, this code would be so
far out of context as to make it incomprehensible.

I don't see anything that would invoke that procedure. It
sort of looks like you expect it to be called automatically,
is this somehow part of a class module that is sinking the
section's Format event? Maybe you are calling this
procedure from some other event procedure??

Access reports automatically invoke each **section's**
Format event only when the section's OnFormat property
contains [Event Procedure]. It seems as if you expect that
to happen for an individual control, but that's not how it
works.

The next misconception I see is that you are trying to
assing the ForeColor to an entire collection of controls in
one statement. That won't work either, you have to assign
the property to each control in the collection.

To make matters even more difficult, there is a gotcha when
using a section's Controls collection. It doesn't work on
Windows NT and XP systems - BUMMER!

Here's some AIR CODE that should do what I think you want:

Private Sub Detail_Format( . . .
Dim ctl As Control

If InStr(1, somecontrol.Value, "OPTION") Then
For Each ctl In Me.Controls
If ctl.Section = 0 Then 'only detail section
If ctl.ControlType = acTextbox _
Or ctl.ControlType = acLabel _
Then ' only text boxes and labels
Me.txtDescription.FontBold = True
Me.txtDescription.ForeColor = vbRed
Me.txtDescription.FontSize = 24
Else
Me.txtDescription.FontBold = False
Me.txtDescription.ForeColor = vbBlack
Me.txtDescription.FontSize = 12
End If
End If
Next ctl
End If
 
Jay said:
Thank You for your response. The reason for the unfamiliarity by you is
that this is code behind a Visual Basic Data Report not ACCESS per sey.
Here is the entire code. The only reason that I posted it here is because I
couldn't find a data reports news group. Maybe you could point me to one?

I don't have an event called Detail_Format like you mentioned (that is
ACCESS reports only). I don't believe that the code that you provided would
work for me.

Sorry, Jay. Since I've never used a Data Report, I don't
see how I can help you.
 
VB DataReports should allow you to set a break point in the code. However, I
wouldn't use DataReports in VB for anything other than the simplest of data
presentation. Access reports are infinitely more flexible and easy to
program. You might also want to consider Cyrstal Reports.

--
Duane Hookom
MS Access MVP


Jay said:
Thank You for your response. The reason for the unfamiliarity by you is
that this is code behind a Visual Basic Data Report not ACCESS per sey.
Here is the entire code. The only reason that I posted it here is because I
couldn't find a data reports news group. Maybe you could point me to one?

I don't have an event called Detail_Format like you mentioned (that is
ACCESS reports only). I don't believe that the code that you provided would
work for me.

The withevents that I declared caused these events show up in the drop down
events list.

Thank You for any input on this matter. It is important to my client!

Jay

Option Explicit

Dim WithEvents myStdData As StdDataFormat
Dim WithEvents myDescData As StdDataFormat
Dim WithEvents myDescription As StdDataFormat

Private Sub DataReport_Initialize()
Set myStdData = New StdDataFormat
Set myDescData = New StdDataFormat
Set myDescription = New StdDataFormat

Set
Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtSubOrder").DataFormat
= myStdData
Set Me.Sections("cmdEstimateNew_Header").Controls("txtOptionI").DataFormat
= myDescData
Set
Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").DataFor
mat = myDescription
End Sub

Private Sub myStdData_Format(ByVal DataValue As StdFormat.StdDataValue)
If DataValue.Value = "0" Then
DataValue = ""
End If
End Sub

Private Sub myDescData_Format(ByVal DataValue As StdFormat.StdDataValue)
If DataValue.Value = 0 Then
DataValue.Value = "True"
End If
End Sub
Private Sub myDescription_Format(ByVal DataValue As StdFormat.StdDataValue)
If InStr(1, DataValue.Value, "OPTION") Then

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.Bo
ld = True

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").ForeCol
or = vbRed
End If
End Sub

font
and
maybe change the forecolor
Private Sub myDescription_Format(ByVal DataValue As StdFormat.StdDataValue)
If InStr(1, DataValue.Value, "OPTION") Then

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.B
o
ld = True

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").ForeCo
l
or = vbRed

Me.Sections("cmdEstimateSpecsNew_Detail").Controls("txtDescription").Font.S
i
ze = 24

End If
End Sub


I'm not even convinced that this is VBA code. What variable
type is StdFormat.StdDataValue? Even if that's some legal
construct that I've never seen before, this code would be so
far out of context as to make it incomprehensible.

I don't see anything that would invoke that procedure. It
sort of looks like you expect it to be called automatically,
is this somehow part of a class module that is sinking the
section's Format event? Maybe you are calling this
procedure from some other event procedure??

Access reports automatically invoke each **section's**
Format event only when the section's OnFormat property
contains [Event Procedure]. It seems as if you expect that
to happen for an individual control, but that's not how it
works.

The next misconception I see is that you are trying to
assing the ForeColor to an entire collection of controls in
one statement. That won't work either, you have to assign
the property to each control in the collection.

To make matters even more difficult, there is a gotcha when
using a section's Controls collection. It doesn't work on
Windows NT and XP systems - BUMMER!

Here's some AIR CODE that should do what I think you want:

Private Sub Detail_Format( . . .
Dim ctl As Control

If InStr(1, somecontrol.Value, "OPTION") Then
For Each ctl In Me.Controls
If ctl.Section = 0 Then 'only detail section
If ctl.ControlType = acTextbox _
Or ctl.ControlType = acLabel _
Then ' only text boxes and labels
Me.txtDescription.FontBold = True
Me.txtDescription.ForeColor = vbRed
Me.txtDescription.FontSize = 24
Else
Me.txtDescription.FontBold = False
Me.txtDescription.ForeColor = vbBlack
Me.txtDescription.FontSize = 12
End If
End If
Next ctl
End If
 
Back
Top