Require VBA for the following Report Formatting Algorithm

ions

Access User
Local time
Yesterday, 23:57
Joined
May 23, 2004
Messages
823
Below is the algorithm I require. I am not very familiar with the VBA syntax required to make this algorithm work.

The purpose of the algorithm is to add underline to conditional formatting when the report is in Report View to mimic a hyperlink and to remove the underline when the report is in Print Preview.

Code:
'Example Call

Call UnderlineCondFormat(Reports("myReport"), acViewPreview)

Public Sub UnderlineCondFormat(rpt As Report, intReportView As Integer)

    'Cycle through each section of the report.
        'Cycle through each control in the section.
            'If the control is a subReport recursive call to UnderlineCondFormat
                UnderlineCondFormat(ctrl.Report, intReportView)
            Else

                If the ctrl has Tag = "Conditional HyperLink"
                    Cycle through all the conditional formatting
                        If intReportView = acViewPreview
                            Remove underline from the conditional format.

                        Else 'acViewReport
                            Add underline to the conditional format.
                        End If
                    Loop
                End If
            End If
        Loop
    Loop


End Sub
 
Last edited:
Something like this should work:

In the detail section of your report under the OnFormat event put something like this:

Me.[ControlName].FontUnderline = False

and then still within the detail section but under the OnPaint event put something like this:

Me.[ControlName].FontUnderline = True

NB: Just swap ControlName for the actual name of the control on your report.
 
James,

Thanks for your reply.

I need this to work for conditional formatting.

ex. Me.MyControl.FormatConditions(0).FontUnderline = False

1. If I put the above on the OnFormat it will run for each record. If there are 1000's of records this is not efficient.

2. I get a RunTime error (2191) if I try to change Conditional formatting in OnFormat.
 
I maybe wrong but I don't think you can set conditional formatting without going into design view. I'll take a look later.
 
You can set conditional formatting in the Open Event in any view.

I tried the below code but it always makes the control red?

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me.Registered = False Then
       Me.WasteClass.ForeColor = RGB(255, 0, 0)
       Me.WasteClass.FontUnderline = False

    End If
End Sub

Private Sub Detail_Paint()
    If Me.Registered = False Then
       Me.WasteClass.ForeColor = RGB(255, 0, 0)
       Me.WasteClass.FontUnderline = True
    End If
End Sub
 
Last edited:
It's always setting it to red because you're telling it to with the following line:

Me.WasteClass.ForeColor = RGB(255, 0, 0)

WHat re you trying to do?
 
i struggle to see how you can do this

report preview is just another way of visualising the report. i cannot imagine there is a way of changing the appearance from one way to another. it's still the same report.
 
Thanks for your responses.

I managed to achieve what I wanted.

Here is an example from one of the reports in the report's On Open Event.

Code:
If Me.CurrentView = gintCurrentViewPreview Then  'Can't use OpenReport constants here because CurrentView has different constants
    Me.GeneratorNumber.FormatConditions(0).FontUnderline = False
Else 'Print Preview
    Me.GeneratorNumber.FormatConditions(0).FontUnderline = True
End If

It was a little more difficult for the Reports that had subreports but I managed to get it to work using a trick.

Also I learned that Report View functions like a continuous form. What you do to one control happens to all. That is why my OnPaint function made everything red.
 

Users who are viewing this thread

Back
Top Bottom