VBA Report Grouping

M

Marshall Barton

SteveSal said:
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.
 
K

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 ")
 
K

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"

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
 
M

Marshall Barton

Wow, that's one of the easiest ways I have ever solved a
problem. Just wait a half hour and the answer magically
appears ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top