hke72
asked on
Working with OldValue in form
I have a statusfield which causes problems. If a user change information in other controls in the form so that it is "Dirty" I do not have access to the OldValue of my statusfield (the user is only allowed to change status in defined ways). If I save the record first it is not a problem, but why?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK some basic questions.
What Version of Access?
Are you inserting a new record or updating an existing record? If you are inserting the record then the OldValue will not be set.
How does the user change the Statusfield?
Cheers, Andrew
What Version of Access?
Are you inserting a new record or updating an existing record? If you are inserting the record then the OldValue will not be set.
How does the user change the Statusfield?
Cheers, Andrew
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I thought of this (I think), but it is not a new record - if it was I could understand, but it is only "Dirty".
To explain a bit more they have [Approved By], and [Status] and when they change status to 'approved' [Approved by] is set with the network username. This works fine. What happend was that a user first set [Approved by] and then changed the statusfield to approved. When debugging using watch and checking the OldValue of [Status] it sais "Reserved error" in the OldValue!? But if I update the record after choosing [Approved by] it gives me the correct OldValue.
To explain a bit more they have [Approved By], and [Status] and when they change status to 'approved' [Approved by] is set with the network username. This works fine. What happend was that a user first set [Approved by] and then changed the statusfield to approved. When debugging using watch and checking the OldValue of [Status] it sais "Reserved error" in the OldValue!? But if I update the record after choosing [Approved by] it gives me the correct OldValue.
ASKER
To Andrew,
What Version of Access? - 2003.
Are you inserting a new record or updating an existing record? - updating
If you are inserting the record then the OldValue will not be set. - I know, but thank you
How does the user change the Statusfield? - It is a combobox and I run a check in Status_BeforeUpdate. The user can approve something, but not go from Approved back to an earlier Status. As long as the record has been updated first - it is not a problem, but I do not like the idea of updating the record for the user to often.
What Version of Access? - 2003.
Are you inserting a new record or updating an existing record? - updating
If you are inserting the record then the OldValue will not be set. - I know, but thank you
How does the user change the Statusfield? - It is a combobox and I run a check in Status_BeforeUpdate. The user can approve something, but not go from Approved back to an earlier Status. As long as the record has been updated first - it is not a problem, but I do not like the idea of updating the record for the user to often.
So if I am understanding this correctly it is due to the fact that the user is updating the combobox and when the user does this it works fine unless the first thing that is being updated is the status itself and this is therefore due to the BeforeUpdate event happening before the OldValue properties are set.
Does that sound correct?
Cheers, Andrew
Does that sound correct?
Cheers, Andrew
Note that OldValue for any control remains in effect *until* the entire record is saved.
mx
mx
Hi mx does that imply that my summation is correct, because it is the BeforeUpdate event being triggered on the first field that is being updated the OldValue is currently not set?
Cheers, Andrew
PS long time since i relied on bound forms
Cheers, Andrew
PS long time since i relied on bound forms
ASKER
Dear Andrew - no :)
If the user choose Status - everything is fine, but what he did was to first set another value (Approved By) and then try to choose Status.
If the user choose Status - everything is fine, but what he did was to first set another value (Approved By) and then try to choose Status.
ASKER
--Note that OldValue for any control remains in effect *until* the entire record is saved.
--mx
I did not get that one? By in effect you mean?
Hans Kristian
--mx
I did not get that one? By in effect you mean?
Hans Kristian
"I did not get that one? By in effect you mean?"
I mean that ... if you change a controls value ... then move to some other control, etc., the OldValue of the first control is still the same value (even though AfterUpdate for that control has occured) ... and will remain that value until the entire record is saved - at which to 'new' OldValue will be the 'new' value entered.
mx
I mean that ... if you change a controls value ... then move to some other control, etc., the OldValue of the first control is still the same value (even though AfterUpdate for that control has occured) ... and will remain that value until the entire record is saved - at which to 'new' OldValue will be the 'new' value entered.
mx
As stated it is a long time since I spent much time on bound forms so I have just ran a little test, the bound textbox was set to "Smith" and the code was run in the OnClick of a Command Button
MsgBox Me.Surname.OldValue 'Smith
Me.Surname = "Jones"
MsgBox Me.Surname.OldValue 'Smith
Me.Dirty = False
MsgBox Me.Surname.OldValue 'Jones
And my conclusion is that the OldValue is always available but may not be what you are expecting depending on the events that are being triggered. Try and break up all the events and check the value at each stage.
Cheers, Andrew
MsgBox Me.Surname.OldValue 'Smith
Me.Surname = "Jones"
MsgBox Me.Surname.OldValue 'Smith
Me.Dirty = False
MsgBox Me.Surname.OldValue 'Jones
And my conclusion is that the OldValue is always available but may not be what you are expecting depending on the events that are being triggered. Try and break up all the events and check the value at each stage.
Cheers, Andrew
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER