Dynamic title in ms access report (1 Viewer)

Sokkheng

Member
Local time
Today, 18:28
Joined
Jul 12, 2023
Messages
34
I create report that start from month to month, so the user can select month from the form that have two combo box
cboMonthStart and cboMonthEnd.
In report title i want it dynamic title refer to the user select month example the user select from Jan to Feb the title is
"Report from Jan to Feb" if user select month Jan to Jan so the title is "Report for the month Jan".
Mean i want compare two combo box if user select only one month it show title one if user select different month it show title two.
Please guide me how to do?
Thanks
Sokkheng
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:28
Joined
May 7, 2009
Messages
19,244
if the form is still Open when you open the report, you can add code to the Report's Open event to set the title (label control?).

Code:
Private Sub Report_Open(Cancel As Integer)
dim sTitle As String
dim frm As Form
set frm = Form!NameOfFormThatHas2Combo
With frm
sTitle ="Report for the month of " & ![Combo1]
if ![Combo1] <> ![Combo2] Then
    sTitle = sTitle & " to " & ![Combo2]
End If
End With
set frm=nothing
Me.TitleLabel.Caption = sTitle
End Sub
 

ebs17

Well-known member
Local time
Today, 13:28
Joined
Feb 7, 2020
Messages
1,946
If you work with month names, you are making things unnecessarily difficult for yourself. It is more efficient to define a desired period using the start date and end date. This allows you to filter directly, and the user also understands such information as a heading. In addition, you are much more variable with regard to possible time periods.

Code:
DoCmd.OpenReport "YourReport", acViewNormal, , _
    "DateField BETWEEN " & Format(Me.cboStartDate, "\#yyyy\-mm\-dd\#") & " AND " & Format(Me.cboEndDate, "\#yyyy\-mm\-dd\#"), , _
    Me.cboStartDate & "|" & Me.cboEndDate

'-----------------------------------------------------------------------------------------------------------

Private Sub Report_Open(Cancel As Integer)
   Dim sTitle As String
   If Not IsNull(Me.OpenArgs) Then
      sTitle = "Report from " & Split(Me.OpenArgs, "|")(0) & " to " & Split(Me.OpenArgs, "|")(1)
      Me.TitleLabel.Caption = sTitle
   End If
End Sub
 
Last edited:

Sokkheng

Member
Local time
Today, 18:28
Joined
Jul 12, 2023
Messages
34
follow your instructions now I'm solve the problems, thanks for any help.
Sokkheng
 

Sokkheng

Member
Local time
Today, 18:28
Joined
Jul 12, 2023
Messages
34
please one more thing, I want to group my text box in ms access report for easy to move position or arrange it.
Thanks
 

Users who are viewing this thread

Top Bottom