dynamic report header

deb

Active Member
Joined
Feb 1, 2003
Messages
396
Access 365

I have a QBF with a combobox "CboGrouping" that tells the report the tow grouping the user wants. (code from Allen Brown)
Now I need to add the correct fields in the Header area...
i.e. if case 1, then District Header would be [District] and District Header would be [District]
if case 2 District Header would be [District] and District Header would be [District]



Private Sub Report_Open(Cancel As Integer)


Select Case Forms!f_QBF!cboGrouping
Case "1" 'Site & District
Me.GroupLevel(0).ControlSource = "Site"
Me.GroupLevel(1).ControlSource = "District"


Case "2" 'District & Site
Me.GroupLevel(0).ControlSource = "District"
Me.GroupLevel(1).ControlSource = "Site"

End Select
End Sub
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

stumac

Active Member
Joined
Jul 16, 2010
Messages
471
Add 2 unbound controls to your report and set the the same way you are setting your GroupLevel:


You will need to change the name of the controls to match what you name your unbound controls.

Code:
Private Sub Report_Open(Cancel As Integer)




Select Case Forms!f_QBF!cboGrouping
Case "1" 'Site & District
Me.GroupLevel(0).ControlSource = "Site"
Me.GroupLevel(1).ControlSource = "District"
Me.[COLOR=#ff0000]Text1[/COLOR].ControlSource = "Site"
Me.[COLOR=#ff0000]Text2[/COLOR].ControlSource = "District"


Case "2" 'District & Site
Me.GroupLevel(0).ControlSource = "District"
Me.GroupLevel(1).ControlSource = "Site"
Me.[COLOR=#ff0000]Text1[/COLOR].ControlSource = "District"
Me.[COLOR=#ff0000]Text2[/COLOR].ControlSource = "Site"


End Select
End Sub
 

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
709
Could you have ?
Rich (BB code):
Private Sub Report_Open(Cancel As Integer)

Select Case Forms!f_QBF!cboGrouping
Case "1" 'Site & District
    Me.GroupLevel(0).ControlSource = "Site"
    Me.GroupLevel(1).ControlSource = "District"


Case "2" 'District & Site
    Me.GroupLevel(0).ControlSource = "District"
    Me.GroupLevel(1).ControlSource = "Site"

End Select
Me.Text1.ControlSource = Me.GroupLevel(0).ControlSource
Me.Text2.ControlSource = Me.GroupLevel(1).ControlSource
End Sub
Well done for interpreting that from the original post as well. :confused:
 

Forum statistics

Threads
1,089,172
Messages
5,406,596
Members
403,097
Latest member
danielcarrington

This Week's Hot Topics

Top