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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

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
822
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,102,601
Messages
5,487,795
Members
407,610
Latest member
bellakim00

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top