Returning back to Original value

T

trekgoes2malaysia

I am trying to figure out how I can reset a value from a list box on
a form to its original value if the new selection a user chooses
violates a condition in my code (in this case a MsgBox would appear
asking the user to go back and select a different item). My problem
is that when VBA returns the user back to the screen page, the
selection has been changed to the last entry the user chose and not
the original.

The code is in an "On Change" event procedure. I tried capturing the
original value using a separate event procedure "Before_Update" which
I call in the "On Change" one but it would only return a 0 value since
it is likely not reading the variable from the before_update procedure
properly.


' Checking to make sure no lap times exist if user is trying to
reduce the effor tdistance
For i = 2 To j
If z(i) > getdistance And (IsNull(Me("t" & i)) = False )
Then
MsgBox ("Before changing effort distance, you must
delete lap times for distances greater than " & getdistance & "m")
Me![Effort Distance:] = Me![Effort Distance:].Undo
Exit Sub
End If
Next
Any suggestions on how to resolve this?

Thanks
Patrick
 
A

Albert D. Kallal

for "most" verification code, use the controls before update event, and if
you have to cancel the even, you go:

MsgBox ("Before changing effort distance, you must
delete lap times for distances greater than " & getdistance &
"m")

cancel = true
exit sub

setting the cancel = true will force/prevent the user from leading the
control.....

note that on-change does NOT have a cancel event, but the before update
event does.....

The before update event does NOT fire if the user does not change the value
of the control.
 
T

TonyT

If you use the BeforeUpdate event of the listbox, you can refer to the
Oldvalue (Me.myListBox.OldValue) and you also have the option to cancel the
update. If for some reason you can't have the code in the listbox's event,
then you will have to declare a private form level variable and set that to
..OldValue (in the listbox's BeforeUpdate event) and then refer to that.
Also you can't call a controls BeforeUpdate event from the OnChange event.

What is this piece of code trying to do;
(IsNull(Me("t" & i)) = False )
I think that needs re-working

hth
 

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