Setting TextBox value based on WhereCondition value:

  • Thread starter Thread starter zakhan
  • Start date Start date
Z

zakhan

Hello,

I have read a lot of previous emails that relate to this issue but
still can't figure out how to do this (which should be possible because
it seems like such a common usecase):

I am opening a Report using VBA from my Visual Basic application using
the DoCmd.OpenReport function. Basically the user builds the
'whereCondition' graphically in the VB app and this is passed onto the
Report in the whereCondition.

Now on the Report there is a TextBox which should be populated with one
of the parameter values in the whereCondition (I get this value after
some nasty splitting). However, I am unable to get the Filter value in
the Report_Open event method (as I have read from some previous posts,
this is a Microsoft 'feature').

So the next logical thing for me to do was to put it in the
PageHeaderSection_Format method but even though we have the Filter
value, it is too late to set the TextBox ControlSource by that time!

Basically this doesn't work:

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
fltr = Me.Report.Filter
tokens = Split(fltr, "#")
monthYearDt = tokens(1)
Me.MonthYearVal.ControlSource = "=#" + monthYearDt + "#"
End Sub

It gives me the following error:
"You can't set the ControlSource property in Print Preview or after
printing has started..."

Can someone please point me in the right direction?

Thank you.
 
You can try set the Value rather than the Control Source.
Me.MonthYearVal.Value = "=#" & monthYearDt & "#"
Make sure that MonthYearVal text box doesn't have a control source.
 
Thanks.

This works. I had already tried what you said but MonthYearVal had a
control source so it would not let me set the value.

As an aside, I discovered the OpenArgs param while ploughing through
these forums and I'm using that instead of the whereCondition.
 
OpenArgs are a fairly recent addition to Access Reports. Glad to hear you
found this solution.
 
Back
Top