VBA : Update unbound text box title with variable

Nyanko

Registered User.
Local time
Today, 10:25
Joined
Apr 21, 2005
Messages
57
Hi,

I have a form with a combo box to control the parameter running a report. It's a year select and I would like to add this year to an unbound text box in the Report Header.

Code:
If Me.[cmb_CashFlow] = "Run" Then
        If Me.cmb_FinancialYear = "All" Then
            FYtitle = "All"
            DoCmd.OpenReport "Rpt_CashFlow", acViewPreview
            Me!txt_FY.ControlSource = FYtitle
        Else
            FYtitle = Me.cmb_FinancialYear
            strWhere = "FY='" & Me.cmb_FinancialYear & "'"
            DoCmd.OpenReport RptName, acViewPreview, WhereCondition:=strWhere
            Me!txt_FY.ControlSource = FYtitle
        End If
    End If


I'm guessing its because the report is opening in ViewPreview. How do I open in edit mode, update the txtbox and show in Preview ?
 
use openargs, its the fifth argument:

DoCmd.OpenReport "Rpt_CashFlow", acViewPreview,,,,FYTitle

DoCmd.OpenReport RptName, acViewPreview, WhereCondition:=strWhere, OpenArgs:=FYTitle

now on your reports load or open event:

private sub report_load()
dim strArg as string
strArg = Me.OpenArgs & ""
if strArg <> "" then Me!txt_FY.Value = strArg
end sub
 
This worked perfectly. Thank you
 

Users who are viewing this thread

Back
Top Bottom