Setting Control source in a subreport

  • Thread starter Thread starter Judy
  • Start date Start date
J

Judy

I'm trying to set the control source of several text boxes in a
subreport based on information from a form. After researching on this
forum, I learned that needed to add the following code to verify it is
the first time the form is loading.


Static Initialized As Boolean
If Not Initialized Then
Me.textbox.ControlSource = whatever
Initialized = True
End If
End Sub

This work to just set the control sources, but when I add the logic to
decide what to set the control sources to, i get the original message
about not being able to set the control source in print preview mode
etc. I put the logic after the If statement:

Static Initialized As Boolean
If Not Initialized Then
If(Forms![Lock]![FP] < 0) Then
Me.TextBox.ControlSource = "=[Forecast]"
End If
Initialized = True
End If
End Sub

Thanks, Judy
 
Judy, there are timing problems with trying to do this in a subreport.

Could you use an IIf() expression, or perhaps Switch() or Choose() in the
Control Source? Set it up that way at design time.

This example shows the value of the Forecast field if the FP text box on the
form is less than zero, else it shows the value of the Actual field:
=IIf([Forms]![Lock]![FP] < 0, [Forecast], [Actual])

Make sure the Name of this text box is not the same as a field name, e.g. it
must not be named Forecast.
 
Thank you, Allen. I actually have 14 cases to check, so iff won't
work. I will investigate Switch and Chose. Thanks so much. Judy
 
Back
Top