473,224 Members | 1,466 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,224 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 2644
"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...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.