Auto change the value/data of control base on another control (1 Viewer)

moi

Member
Local time
Today, 13:30
Joined
Jan 10, 2024
Messages
197
Hello all,

How will i auto change the status confrol from "Active" to "Fully Paid" if my balance control value is "0"..my balance control is a calculated control in my main table..

Thank you all.
 

GaP42

Active member
Local time
Today, 15:30
Joined
Apr 27, 2020
Messages
338
Perhaps using an iif statement in the status control (expression builder) itself:
Code:
=IIf([IsPd]=-1,"Fully Paid","Not Fully Paid")
where you use iif txtBalance = 0 ?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:30
Joined
Feb 28, 2001
Messages
27,186
The way you explained that leaves ambiguities. Are you talking about a form with a control that contains a calculation? Or is the calculation due to having a calculated field in a table? You mixed contexts in your question so it might be hard for us to answer without clarification.

Not that it CAN'T be answered, but at least I am not sure which of two or more ways to answer. So tell us more about the situation.
 

moi

Member
Local time
Today, 13:30
Joined
Jan 10, 2024
Messages
197
Hi the-doc-man,

The calculated contorol is based on 2 controls, 1) TCP is from table which the form source, 2) SUM control from a subform within the form.

Now the control i would like to based the auto change is "balance"..

My appologies guys if i can't explained well..
 

moi

Member
Local time
Today, 13:30
Joined
Jan 10, 2024
Messages
197
Perhaps using an iif statement in the status control (expression builder) itself:
Code:
=IIf([IsPd]=-1,"Fully Paid","Not Fully Paid")
where you use iif txtBalance = 0 ?
Hi,

How would i use this, i dont want to remove the default value "Active" of the Status control if the balance is not = to "0" zero.
 

GaP42

Active member
Local time
Today, 15:30
Joined
Apr 27, 2020
Messages
338
Assume your StatusControl displays either "Active" or "Fully Paid" (a control bound to the data item "Status") and you have a control Balance. Balance is a calculated value and may display values >0, <0 or 0. When the Balance = 0 then the StatusControl should display "Fully Paid".
If this is the situation, then you need to update the value of the item "Status" when Balance = 0. That could be achieved in the BeforeUpdate event of the form where Balance is shown:
Code:
if Balance = 0 then
  Status = "Fully Paid"
else
 Status = "Active"
end if
When the record is updated, immediately after the successful completion of the BeforeUpdate event of the form, the record will show the appropriate Status in the StatusContol

If, on the otherhand, your StatusControl is an unbound control, the display can show either "Active" or "Fully Paid" depending on the value of Balance. In the unbound StatusControl, enter the following as the ControlSource:
Code:
=IIf([Balance]=0,"Fully Paid","Active")
The value of the StatusControl is not saved to the Status, unless you take further steps similar to the above.
 
  • Like
Reactions: moi

moi

Member
Local time
Today, 13:30
Joined
Jan 10, 2024
Messages
197
Assume your StatusControl displays either "Active" or "Fully Paid" (a control bound to the data item "Status") and you have a control Balance. Balance is a calculated value and may display values >0, <0 or 0. When the Balance = 0 then the StatusControl should display "Fully Paid".
If this is the situation, then you need to update the value of the item "Status" when Balance = 0. That could be achieved in the BeforeUpdate event of the form where Balance is shown:
Code:
if Balance = 0 then
  Status = "Fully Paid"
else
Status = "Active"
end if
When the record is updated, immediately after the successful completion of the BeforeUpdate event of the form, the record will show the appropriate Status in the StatusContol

If, on the otherhand, your StatusControl is an unbound control, the display can show either "Active" or "Fully Paid" depending on the value of Balance. In the unbound StatusControl, enter the following as the ControlSource:
Code:
=IIf([Balance]=0,"Fully Paid","Active")
The value of the StatusControl is not saved to the Status, unless you take further steps similar to the above.
Thank you very much GaP42, well explain.. Maybe your first code is the suitable one, because my Status control is bound..

Again thank you..
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:30
Joined
Feb 19, 2002
Messages
43,275
It is poor practice to save two data fields that have the same meaning. You can always tell the status by checking the Balance. Keeping the Balance in itself is a violation because the Balance represents the sum of other data so just try to limit your design to the minimum number of poor design choices.
 

GaP42

Active member
Local time
Today, 15:30
Joined
Apr 27, 2020
Messages
338
It is poor practice to save two data fields that have the same meaning. You can always tell the status by checking the Balance. Keeping the Balance in itself is a violation because the Balance represents the sum of other data so just try to limit your design to the minimum number of poor design choices.
@moi indicated that Balance is a calculated control - which may not be stored. Not sure in this particular case, but it is sometimes the case that the calculated extended price is stored as it is calculated on perhaps transient values - eg a discount rate that may be subject to later change. The determination of a Balance and "Fully Paid" status are both determined by calculation - retaining either or one or the other is based on assessment of the overhead.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:30
Joined
Feb 19, 2002
Messages
43,275
As we all know, the storing of calculated values leaves you open to data anomolies. You need code in a number of places to handle this so that whenever one of the underlying items changes, the total is always updated. Not everyone gets this right. Also, people who take over the application at a later time might not realize that this violation exists and not cater to it.

Put lots of comments everywhere so that no one will miss them.
 

Users who are viewing this thread

Top Bottom