BountyBob
10-20-2004, 06:44 AM
Hi guys,
I have a lookup form which allows a database table to be updated. What I'm trying to implement is an Undo/Redo feature which would allow a user, before the record is saved, to Undo or Redo edits to the current record.
The way I have tried implementing this is by maintaining a collection of Edits. The collection elements (Edits) hold the Control that was edited, the Pre-Update value and the Post-Update value.
When a user enters a control (ie. textbox/listbox) the GotFocus event is called which initialises a collection element with the control name and the pre-update value.
When a user leaves a control, the LostFocus event is called which inserts the post-update value.
An integer pointer is maintained which points to the current collection element. All the while the user is making changes, this points to the last element in the collection.
When a user "undoes" an operation, the pointer replaces the Post-Update value with the Pre-Update value and decrements the pointer.
When a user "redoes" an operation, the pointer replaces the Pre-Update value with the Post-Update value and increments the pointer.
This all works fine until I click on another form. At this point, the Lost_Focus event for the current control is executed, incrementing the pointer. If I keep switching between forms, the pointer is executed each time and screws up my undo collection.
Can anyone suggest a better way of doing this?
Cheers in advance,
Rob Small
I have a lookup form which allows a database table to be updated. What I'm trying to implement is an Undo/Redo feature which would allow a user, before the record is saved, to Undo or Redo edits to the current record.
The way I have tried implementing this is by maintaining a collection of Edits. The collection elements (Edits) hold the Control that was edited, the Pre-Update value and the Post-Update value.
When a user enters a control (ie. textbox/listbox) the GotFocus event is called which initialises a collection element with the control name and the pre-update value.
When a user leaves a control, the LostFocus event is called which inserts the post-update value.
An integer pointer is maintained which points to the current collection element. All the while the user is making changes, this points to the last element in the collection.
When a user "undoes" an operation, the pointer replaces the Post-Update value with the Pre-Update value and decrements the pointer.
When a user "redoes" an operation, the pointer replaces the Pre-Update value with the Post-Update value and increments the pointer.
This all works fine until I click on another form. At this point, the Lost_Focus event for the current control is executed, incrementing the pointer. If I keep switching between forms, the pointer is executed each time and screws up my undo collection.
Can anyone suggest a better way of doing this?
Cheers in advance,
Rob Small