473,385 Members | 1,357 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,385 software developers and data experts.

Can't .Undo Date control

Lyn
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 immediately validated. If the
data entered is considered valid, focus moves to the next control in the tab
sequence. So far, so good.

If the data entered in StartDate is considered invalid, an error message is
displayed via MsgBox. When OK is clicked, the statement "Me!StartDate.Undo"
is executed. I was expecting that the original data in this control would
be restored and for focus to remain on that data to allow correction.

However, the actual results depends on which event I use to trigger the
validation, none of which gives the expected results:-

1) OnChange:
This event does correctly undo the StartDate data (restoring the original
value) and that original data is selected (has focus) ready for correction.
However, this event is triggered as soon as I change a single character in
the StartDate. Obviously, I want to be able to set the new date completely
before validation occurs, so OnChange is not suitable -- even though it does
the Undo as I would expect.

2) BeforeUpdate:
This event allows the whole field to be updated and validation does not
occur until focus is moved off the StartDate control (eg, via using tab).
However, after validation the field is NOT undone (despite the Undo method
statement) and focus moves to the next field, allowing the invalid data to
stand. As a workaround, I have tried to force the focus back to the
StartDate field, but this just gives me an error message "Runtime error
'2108'" which states that the field must be saved before using the SetFocus
method. (BeforeUpdate event occurs before the database is updated.)

3) AfterUpdate:
This event behaves basically the same as in the BeforeUpdate event (without
the workaround). When I apply the workaround to force focus back to
StartDate, the focus instead moves to the next control in tab order
(assuming that I have used tab to trigger validation). To get focus back to
the StartDate field, I have found that I can do two SetFocus statements, the
first one being a dummy one to any other control:-

Me!OtherControl.SetFocus
Me!StartDate.SetFocus

However, this just puts the cursor into the first character position of
StartDate rather than selecting the whole field, and it still doesn't Undo
the updated field value. I have tried Undo then SetFocus, and also SetFocus
then Undo -- no difference.

Am I using the wrong trigger event to validate this field? The Help
suggests using BeforeUpdate or OnChange, but neither of these worked for me.
Am I coding the Undo incorrectly?

Any help appreciated. TIA.

--
Cheers,
Lyn.
Nov 13 '05 #1
2 2651
"Lyn" <lh******@ihug.com.au> wrote in message
news:ce**********@lust.ihug.co.nz...
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 immediately validated. If the
data entered is considered valid, focus moves to the next control in the tab sequence. So far, so good.[snip]


You need to use BeforeUpdate and set the Cancel argument to True when the
validation fails. It is the Cancel that prevents the focus from leaving
the control. Undo is optional, but usually not necessary. Just let the
user see their invalid entry and force them to change it. That is the
behavior you would get from most other validation methods anyway.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


Nov 13 '05 #2
Lyn
Thanks Rick for your response. Setting Cancel was the missing clue.

I found that I did have to set .Undo to make it work the way I wanted. The
difference is that with .Undo not set, the field was undone and the cursor
was positioned at the right end of the data. Setting .Undo also caused the
whole field to be selected for correction. Only a minor difference, but for
me the latter highlights the field that needs correcting more clearly.

But the real solution I was looking for was setting Cancel to True. Thanks
again.

--
Cheers,
Lyn.

"Lyn" <lh******@ihug.com.au> wrote in message
news:ce**********@lust.ihug.co.nz...
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 immediately validated. If the
data entered is considered valid, focus moves to the next control in the tab sequence. So far, so good.

If the data entered in StartDate is considered invalid, an error message is displayed via MsgBox. When OK is clicked, the statement "Me!StartDate.Undo" is executed. I was expecting that the original data in this control would
be restored and for focus to remain on that data to allow correction.

However, the actual results depends on which event I use to trigger the
validation, none of which gives the expected results:-

1) OnChange:
This event does correctly undo the StartDate data (restoring the original
value) and that original data is selected (has focus) ready for correction. However, this event is triggered as soon as I change a single character in
the StartDate. Obviously, I want to be able to set the new date completely before validation occurs, so OnChange is not suitable -- even though it does the Undo as I would expect.

2) BeforeUpdate:
This event allows the whole field to be updated and validation does not
occur until focus is moved off the StartDate control (eg, via using tab).
However, after validation the field is NOT undone (despite the Undo method
statement) and focus moves to the next field, allowing the invalid data to
stand. As a workaround, I have tried to force the focus back to the
StartDate field, but this just gives me an error message "Runtime error
'2108'" which states that the field must be saved before using the SetFocus method. (BeforeUpdate event occurs before the database is updated.)

3) AfterUpdate:
This event behaves basically the same as in the BeforeUpdate event (without the workaround). When I apply the workaround to force focus back to
StartDate, the focus instead moves to the next control in tab order
(assuming that I have used tab to trigger validation). To get focus back to the StartDate field, I have found that I can do two SetFocus statements, the first one being a dummy one to any other control:-

Me!OtherControl.SetFocus
Me!StartDate.SetFocus

However, this just puts the cursor into the first character position of
StartDate rather than selecting the whole field, and it still doesn't Undo
the updated field value. I have tried Undo then SetFocus, and also SetFocus then Undo -- no difference.

Am I using the wrong trigger event to validate this field? The Help
suggests using BeforeUpdate or OnChange, but neither of these worked for me. Am I coding the Undo incorrectly?

Any help appreciated. TIA.

--
Cheers,
Lyn.

Nov 13 '05 #3

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

Similar topics

3
by: Patrick S | last post by:
I am using IE 6.0. On a page, I have placed a contenteditable div which I want to use as a Rich Text Area. I am using the execCommand method of the document to control bold, italics,...
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...
5
by: Lyn | last post by:
Hi, In the BeforeUpdate event of a textbox control I have the following simplified code:- Private Sub StartDate_BeforeUpdate(Cancel As Integer) MsgBox "StartDate Error -- Please Check and...
11
by: Mad Joe | last post by:
I'm using a richTextBox for editing a source code (with Syntax Highlighting) of my own programming language... How come that myRichTextBox doesn't respond to Undo/Redo functions by using default...
0
by: SamSpade | last post by:
Morcillo has a VB6 OCX control based on the riched20.dll. Using it one can type, drag-drop, type, cut, drag-drop, and then undo them one at a time. I have not been able (though I've spent much...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
7
by: ARC | last post by:
I've noticed that if you use code for the before update command for unbound controls, it doesn't really work. I tried the following: Me!ExportedYN.undo Cancel = True DoCmd.CancelEvent Exit...
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...
1
by: Nilam2477 | last post by:
I have RichTextBox control. I want to save the text in a stack for Undo operation each time user changes/updates the Text. I dont to want to use TextBox Base Undo functionality bec i have other...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.