Discussion:
VBA Report Grouping
(too old to reply)
SteveSal
2006-07-17 19:58:02 UTC
Permalink
Does anyone know how I can create report sorts and groupings using VBA only?
Marshall Barton
2006-07-18 00:29:46 UTC
Permalink
Post by SteveSal
Does anyone know how I can create report sorts and groupings using VBA only?
Absolutely not in a running application. The
CreateGroupLevel method is intended only for use in design
time wizards.

The way to deal with this stuff in a running application is
to precreate the group levels and the set the properties in
the report's Open event. See GroupLevel in VBA Help and
come on back if you have a more specific question.
--
Marsh
MVP [MS Access]
Klatuu
2006-08-10 15:46:01 UTC
Permalink
Maybe you can help me remember what I did six months ago.
I have a report where the user is allowed to select the subtotaling. I
control this by making the groupheaders and groupfooters visisble or not
depending on selections.
The problem is, It appears I will also have rearrange the order of the
grouplevels. I know I came up with a way to do this about six months ago,
but I can't remember it and can't find it.
Basically, depending on the user selections, I need to move grouplevel(0) to
grouplevel(3), and grouplevel(5) to to grouplevel(2), etc.

I hate it when my CRS disease kicks in ")
Post by Marshall Barton
Post by SteveSal
Does anyone know how I can create report sorts and groupings using VBA only?
Absolutely not in a running application. The
CreateGroupLevel method is intended only for use in design
time wizards.
The way to deal with this stuff in a running application is
to precreate the group levels and the set the properties in
the report's Open event. See GroupLevel in VBA Help and
come on back if you have a more specific question.
--
Marsh
MVP [MS Access]
Klatuu
2006-08-10 16:18:01 UTC
Permalink
Never Mind, I found it.

Private Sub Report_Open(Cancel As Integer)

On Error GoTo Report_Open_Error

'Activity is always last
Me.GroupLevel(5).ControlSource = "Activity"
With Forms!frmuporeports
'Determine which Subtotals have been selected
'HomeRooom
If .chkHomeRoom Then
Me.GroupLevel(4).ControlSource = "PerformAcctUnit"
Else
Me.GroupLevel(4).ControlSource = Me.GroupLevel(5).ControlSource
End If
'Pool
If .chkPool Then
Me.GroupLevel(3).ControlSource = "Pool"
Else
Me.GroupLevel(3).ControlSource = Me.GroupLevel(4).ControlSource
End If
'BillNetwork
If .chkBillNetwork Then
Me.GroupLevel(2).ControlSource = "BillNetwork"
Else
Me.GroupLevel(2).ControlSource = Me.GroupLevel(3).ControlSource
End If
'MasterActivity
If .chkMActivity Then
Me.GroupLevel(1).ControlSource = "MActivity"
Else
Me.GroupLevel(1).ControlSource = Me.GroupLevel(2).ControlSource
End If
End With
'Top Level For Billable Product Offering
Me.GroupLevel(0).ControlSource = "ProjectId"

Report_Open_Exit:

On Error Resume Next
Exit Sub

Report_Open_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Report_Open of VBA Document
Report_rptUPOProducOffering"
GoTo Report_Open_Exit
End Sub
Post by Klatuu
Maybe you can help me remember what I did six months ago.
I have a report where the user is allowed to select the subtotaling. I
control this by making the groupheaders and groupfooters visisble or not
depending on selections.
The problem is, It appears I will also have rearrange the order of the
grouplevels. I know I came up with a way to do this about six months ago,
but I can't remember it and can't find it.
Basically, depending on the user selections, I need to move grouplevel(0) to
grouplevel(3), and grouplevel(5) to to grouplevel(2), etc.
I hate it when my CRS disease kicks in ")
Post by Marshall Barton
Post by SteveSal
Does anyone know how I can create report sorts and groupings using VBA only?
Absolutely not in a running application. The
CreateGroupLevel method is intended only for use in design
time wizards.
The way to deal with this stuff in a running application is
to precreate the group levels and the set the properties in
the report's Open event. See GroupLevel in VBA Help and
come on back if you have a more specific question.
--
Marsh
MVP [MS Access]
Marshall Barton
2006-08-11 15:48:19 UTC
Permalink
Wow, that's one of the easiest ways I have ever solved a
problem. Just wait a half hour and the answer magically
appears ;-)
--
Marsh
MVP [MS Access]
Post by Klatuu
Never Mind, I found it.
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Report_Open_Error
'Activity is always last
Me.GroupLevel(5).ControlSource = "Activity"
With Forms!frmuporeports
'Determine which Subtotals have been selected
'HomeRooom
If .chkHomeRoom Then
Me.GroupLevel(4).ControlSource = "PerformAcctUnit"
Else
Me.GroupLevel(4).ControlSource = Me.GroupLevel(5).ControlSource
End If
'Pool
If .chkPool Then
Me.GroupLevel(3).ControlSource = "Pool"
Else
Me.GroupLevel(3).ControlSource = Me.GroupLevel(4).ControlSource
End If
'BillNetwork
If .chkBillNetwork Then
Me.GroupLevel(2).ControlSource = "BillNetwork"
Else
Me.GroupLevel(2).ControlSource = Me.GroupLevel(3).ControlSource
End If
'MasterActivity
If .chkMActivity Then
Me.GroupLevel(1).ControlSource = "MActivity"
Else
Me.GroupLevel(1).ControlSource = Me.GroupLevel(2).ControlSource
End If
End With
'Top Level For Billable Product Offering
Me.GroupLevel(0).ControlSource = "ProjectId"
On Error Resume Next
Exit Sub
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure Report_Open of VBA Document
Report_rptUPOProducOffering"
GoTo Report_Open_Exit
End Sub
Post by Klatuu
Maybe you can help me remember what I did six months ago.
I have a report where the user is allowed to select the subtotaling. I
control this by making the groupheaders and groupfooters visisble or not
depending on selections.
The problem is, It appears I will also have rearrange the order of the
grouplevels. I know I came up with a way to do this about six months ago,
but I can't remember it and can't find it.
Basically, depending on the user selections, I need to move grouplevel(0) to
grouplevel(3), and grouplevel(5) to to grouplevel(2), etc.
I hate it when my CRS disease kicks in ")
Post by Marshall Barton
Post by SteveSal
Does anyone know how I can create report sorts and groupings using VBA only?
Absolutely not in a running application. The
CreateGroupLevel method is intended only for use in design
time wizards.
The way to deal with this stuff in a running application is
to precreate the group levels and the set the properties in
the report's Open event. See GroupLevel in VBA Help and
come on back if you have a more specific question.
--
Marsh
MVP [MS Access]
Loading...