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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

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
766
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:
 

Watch MrExcel Video

Forum statistics

Threads
1,095,265
Messages
5,443,413
Members
405,234
Latest member
AA90

This Week's Hot Topics

Top