473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with Control's .Undo method

Lyn
Hi,
In the BeforeUpdate event of a textbox control I have the following
simplified code:-

Private Sub StartDate_BeforeUpdate(Cancel As Integer)
[some validation code -- the following code is executed if validation
fails]
MsgBox "StartDate Error -- Please Check and Re-Enter."
Me!StartDate.Undo
Debug.Print "After Undo: " & Me!StartDate
Cancel = True
[Code to reset some other stuff based on the "undone" StartDate]
GoTo ProcEnd
[...]
ProcEnd:
End Sub

When an error occurs, the original textbox value is restored at the end of
the Before Update event by the "Cancel = True" statement. The
"Me!StartDate.Undo" statement does nothing. The Debug.Print still shows the
invalid value.

The online Help for .Undo recommends using this method in the control's
Change event. Is this the only place it can be used for a control? Does it
not work in the BeforeUpdate event? Or am I coding it incorrectly?

The problem is that when the data is found to be invalid, I need to reset
some other fields based on the original value of the text box before leaving
the BeforeUpdate event. If .Undo does not work in this context, maybe I
should be trying .OldValue instead of the Undo method as the basis for
resetting the other stuff?

Any guidance appreciated.

--
Cheers,
Lyn.
Nov 13 '05 #1
5 7084
Lyn
As usually happens when I post a question, I figure out the answer
immediately afterwards. Or at least I think I have in this case. Please
advise if I am right or wrong.

You can't Undo a control while it has focus. But the Catch-22 is that I
can't change focus in the BeforeUpdate event. Maybe I should move all the
code to AfterUpdate? Cancel is not available there, but as I am using a
manual Undo this probably won't matter?

--
Cheers,
Lyn.

"Lyn" <lh******@ihug.com.au> wrote in message
news:d5**********@lust.ihug.co.nz...
Hi,
In the BeforeUpdate event of a textbox control I have the following
simplified code:-

Private Sub StartDate_BeforeUpdate(Cancel As Integer)
[some validation code -- the following code is executed if validation
fails]
MsgBox "StartDate Error -- Please Check and Re-Enter."
Me!StartDate.Undo
Debug.Print "After Undo: " & Me!StartDate
Cancel = True
[Code to reset some other stuff based on the "undone" StartDate]
GoTo ProcEnd
[...]
ProcEnd:
End Sub

When an error occurs, the original textbox value is restored at the end of
the Before Update event by the "Cancel = True" statement. The
"Me!StartDate.Undo" statement does nothing. The Debug.Print still shows
the invalid value.

The online Help for .Undo recommends using this method in the control's
Change event. Is this the only place it can be used for a control? Does
it not work in the BeforeUpdate event? Or am I coding it incorrectly?

The problem is that when the data is found to be invalid, I need to reset
some other fields based on the original value of the text box before
leaving the BeforeUpdate event. If .Undo does not work in this context,
maybe I should be trying .OldValue instead of the Undo method as the basis
for resetting the other stuff?

Any guidance appreciated.

--
Cheers,
Lyn.

Nov 13 '05 #2
Lyn wrote:
As usually happens when I post a question, I figure out the answer
immediately afterwards. Or at least I think I have in this case. Please
advise if I am right or wrong.

You can't Undo a control while it has focus. [snip]


What gave you that idea? Undo is used a LOT in control's BeforeUpdate events
and by definition the control will have focus when that event is running.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #3
Lyn

"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:Lm****************@newssvr12.news.prodigy.com ...
Lyn wrote:

You can't Undo a control while it has focus. [snip]


What gave you that idea? Undo is used a LOT in control's BeforeUpdate
events and by definition the control will have focus when that event is
running.

Rick, thanks for your response.

I stand corrected. In retrospect, I realise that I didn't get an error
message to that effect whereas I have had other situations where this did
occur. I guess I "assumed" (and, yes, I know what "ass-u-me" means :-).

So if that is not the problem, why is Undo not working for me? I have since
got a workaround going where I simply copy .OldValue back into the control.
But isn't this basically what Undo does anyway?

--
Cheers,
Lyn.
Nov 13 '05 #4
Lyn wrote:
Rick, thanks for your response.

I stand corrected. In retrospect, I realise that I didn't get an
error message to that effect whereas I have had other situations
where this did occur. I guess I "assumed" (and, yes, I know what
"ass-u-me" means :-).

So if that is not the problem, why is Undo not working for me? I
have since got a workaround going where I simply copy .OldValue back
into the control. But isn't this basically what Undo does anyway?


Is it a required field? I have also found that Undo does not work as
desired if the control is bound to a required field. In my case it was a
small form with only a few fields so I used Undo on the entire form which
did work.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #5
Lyn

"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:HA****************@newssvr30.news.prodigy.com ...
Is it a required field? I have also found that Undo does not work as
desired if the control is bound to a required field. In my case it was a
small form with only a few fields so I used Undo on the entire form which
did work.

No, it is not a required field, but your response has triggered my addled
brain! The control in question is UNBOUND, so of course Undo won't work!

This is hard to explain, but basically I have a Start Date field in the
table, a corresponding bound but hidden date control on the form, and an
unbound text control which I use to display the date or a message if the
date is special (such as "Unknown"). The unbound field is a copy of the
hidden bound field if the date is a valid one. Applying the Undo to the
bound (hidden) control has resolved the problem.

A case of not seeing the woods for the trees. I think I have been working
on this for too long!

Thanks again for your help. One good thing -- this embarrassment will
ensure that I don't fall for the same problem again!

--
Cheers,
Lyn.
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Laertes | last post by:
In the Form_beforeupdate event : while the command Me.Undo works perfectly the Me.MyControl.Undo doesn't !!! I would like to make it work as I don't want to undo the changes in the whole form, but...
2
by: Lyn | last post by:
Hi, I have a text control on a form which is bound to table field StartDate which is in Date format. When updating the table record via the form, any data entered into the StartDate control is...
1
by: Alex.Wisnoski | last post by:
I have a data entry form with a combo box to look up an entrant's name. If the name is already in the table then it pulls up the record and that part of the form works fine. If the name isn't in...
5
by: Alastair Anderson | last post by:
I have created a very simple form with which I would like to update a single value in a single row of a database as a proof of concept. The relevant parts of the form are a DBWebTextBox (which...
3
by: GoogleEyeJoe | last post by:
Dear ladies and gents, I'm trying to determine whether the .NET Framework implements a means of transactional processing without the need for a database. Essentially, I'd like to enlist...
0
by: .nu | last post by:
#!/usr/bin/env python # -*- coding: utf-8 -*- # Name: Sleepy Hollow # Author: .nu import wx import os import sys
4
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, Does vb2005 have a built-in UnDo feature / object for applications so that I can undo actions like other windows apps? Or do I have to write my own UnDo routine? If vb2005 does have a...
4
by: =?Utf-8?B?Sm9uIEVsbGlz?= | last post by:
Hi All, I want to implement an 'generic' undo by placing a copy of a control in a stack using System.Collections.Generic.Stack. Basically this way I don't need to know if a user has edited text...
7
by: Richard Sherratt | last post by:
I'm trying to stop users deleting an existing value in a field. If they go to an existing record and hit delete, I want to give an error message and reverse the change. The BeforeUpdate event is...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.