Undo doesn't reset unbound controls

E

Eric Norton

I have a scheduling form which has several unbound controls so the user can
identify the schedule they want to work with. Due to the "crosstab with
extras" nature of the scheduling process, I've resorted to using a temporary
table and a Save button (hangs head in shame) that inserts the data back into
the (properly normalised, I promise!) permanent tables.

I want to give the user the option to change their mind if they change one
of the unbound controls to look at a different schedule, without having saved
changes back to the permanent tables.

My problem is that I cannot make the controls return to their original
states, even though I am using Cancel = True and Me!Ctrlname.Undo in the
BeforeUpdate event code for each of the controls. The code runs, generates
no errors, cancels insofar as the AfterUpdate event doesn't fire, but leaves
the control showing its changed value - this is true for two combo boxes and
an option group containing only 2 radio buttons.

Can anybody tell me why this is so, and how to correct this behaviour?

Any assistance or advice (apart from "Don't use a temporary table and
unbound controls" - believe me, I tried to avoid it!) gratefully received!
 
A

Andreas

Don't know why it does this :-(
To resolve the issue, set the controls to Null (Me.Ctrlname=Null) or a
zero length string if Null does not work (Me.Ctrlname="").

Regards,
Andreas
 
E

Eric Norton

Many thanks for the help, Andreas.

Unfortunately the controls may not have been null before they were updated,
and since they are unbound, I can't use the OldValue property either. Maybe
the two things are related - no OldValue property, so no Undoing back to the
original value. Can't see why not though. Anybody from Microsoft reading
this? Why is OldValue restricted to bound controls?
 
E

Eric Norton

I have come up with my own alternative, but it seems such an unwieldy
workaround that I still hope somebody can save me from it.... :)

The workaround is to have an invisible textbox for each control which stores
the current value, and can be used to "reset" the control during the
AfterUpdate event if required, or itself be updated to the new current value
at the end of the AfterUpdate event.
 
A

Andreas

Then you might have to store the "old values" in variables and write
these values back to the controls rather than just hardcoding the values.

Regards,
Andreas
 
K

Ken Snell [MVP]

Bound controls have underlying buffers for storing original, in process of
being edited, and edited data. Unbound controls don't have those buffers.

OldValue uses the buffers to know what the original value was. Therefore,
OldValue and Undo are not available for unbound controls. If you want to
mimic that behavior, use an invisible textbox on the form to hold the
original value of the textbox (put value in that textbox during the form's
Load event and/or other events as appropriate) so that it can be obtained
for putting back in the textbox -- all under your programmatic control.
 
E

Eric Norton

Thanks for that Ken,

As you can see, I came to the same way of coping with this as you suggest,
but it's nice to have someone more experienced confirm it as the best way to
proceed, and to explain why OldValue doesn't work for unbound controls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top