Control source dependent upon value of another control

  • Thread starter Thread starter Joan
  • Start date Start date
J

Joan

Hi,

I have a subform (in continuous forms view) upon which the control source
of one of its' controls is dependent upon the value of another control on
the form. For instance I want the control source of this control to be
ReturnedSalePrice2 if [Returned] Is Not Null, otherwise the control source
should be [SalesPrice]. I tried putting the following code in the subform's
OnLoad event but it doesn't work. I get #Name? in the control instead.
Should this not be on the OnLoad event of the subform? What am I doing
wrong?


Private Sub Form_Load()
If Not IsNull(Me.Returned) Then
Me.SalesPrice.ControlSource = ReturnedSalePrice2
Else
Me.SalesPrice.ControlSource = SalesPrice
End If
End Sub


Joan
 
Use a query like this for the form's record source:

SELECT iif(IsNull(Returned), ReturnedSalePrice2, SalesPrice) FROM MyTable

Pavel
 
Private Sub Form_Load()
If Not IsNull(Me.Returned) Then
Me.SalesPrice.ControlSource = ReturnedSalePrice2
what about SalesPrice.ControlSource = "ReturnedSalePrice2" ?
 
Thanks, Pavel. That worked!


Pavel Romashkin said:
Use a query like this for the form's record source:

SELECT iif(IsNull(Returned), ReturnedSalePrice2, SalesPrice) FROM MyTable

Pavel
Hi,

I have a subform (in continuous forms view) upon which the control source
of one of its' controls is dependent upon the value of another control on
the form. For instance I want the control source of this control to be
ReturnedSalePrice2 if [Returned] Is Not Null, otherwise the control source
should be [SalesPrice]. I tried putting the following code in the subform's
OnLoad event but it doesn't work. I get #Name? in the control instead.
Should this not be on the OnLoad event of the subform? What am I doing
wrong?

Private Sub Form_Load()
If Not IsNull(Me.Returned) Then
Me.SalesPrice.ControlSource = ReturnedSalePrice2
Else
Me.SalesPrice.ControlSource = SalesPrice
End If
End Sub

Joan
 
Back
Top