473,500 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to undoing a TextBox

53 New Member
Hi all.
I wanted to change value of a TextBox to previous value of that TextBox when a user types some special data but i couldn't change value in BeforeUpdate or AfterUpdate Event handler!
Is any special command or method exists to undo only one TextBoxe's value of a form?
Thanks in advanced
Jul 1 '10 #1
7 9989
ADezii
8,834 Recognized Expert Expert
@alinagoo
Let's say that you have a 'Bound' Field on a Form named [Margin]. Let's also suppose that if at any time, a User enters a Margin of > 10 into this Field for an existing Record, you then wish to restore the Original Value of that Field. In the AfterUpdate() Event of the [Margin] Field:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Margin_AfterUpdate()
  2. Dim ctlTBox As TextBox
  3.  
  4. Set ctlTBox = Me![Margin]
  5.  
  6. If ctlTBox > 10 Then
  7.   ctlTBox = ctlTBox.OldValue
  8. End If
  9. End Sub
Jul 1 '10 #2
missinglinq
3,532 Recognized Expert Specialist
What exactly did you try?

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBoxName_AfterUpdate()
  2.  If Me.TextBoxName.Value = "9999" Then
  3.   Me.TextBoxName.Value = Me.TextBoxName.OldValue
  4.  End If
  5. End Sub
should work, replacing 9999 with the triggering value. Omit the quotes, of course, if the value is Numerical instead of Text.

Linq ;0)>
Jul 1 '10 #3
NeoPa
32,557 Recognized Expert Moderator MVP
I don't know what you tried but cancelling an update if the value doesn't fit is pretty straightforward :
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextBox_BeforeUpdate(Cancel As Integer)
  2.     If Me.YourTextBox = "Invalid Value" Then Cancel = True
  3. End Sub
Jul 1 '10 #4
alinagoo
53 New Member
Thanks you all
But NeoPa's method does not worked properly and the method used by Missinglinq and ADezii with OlaValue property works fine.
Good Luck
Jul 1 '10 #5
NeoPa
32,557 Recognized Expert Moderator MVP
NeoPa's method should work if done properly. What did you try (This was asked before)?
Jul 1 '10 #6
alinagoo
53 New Member
@NeoPa
I used "Cancel = True" in BeforeUpdate Event handler of a TextBox to convert value of that TextBox to previous saved value if newly typed value is not in a valid range but it does not work!

Thank
Good Luck
Jul 2 '10 #7
NeoPa
32,557 Recognized Expert Moderator MVP
My mistake. The Cancel = True simply stops the cursor leaving the control. Attempting to set the value in a BeforeUpdate() event procedure always triggers an error, so the trick to doing it properly is to use the .Undo() method.

Using ADezii's situation as an example :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Margin_BeforeUpdate(Cancel As Integer)
  2.     With Me.Margin
  3.         If .Value > 10 Then
  4.             Call .Undo
  5.             Cancel = True
  6.         End If
  7.     End With
  8. End Sub
This leaves the cursor in the control, as well as reverting the data to that before any changes were attempted.
Jul 2 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2098
by: Jonas L | last post by:
Hi, I need to create a textbox which acts as a normal textbox but with the following extra requirements: 1) In-focus color, when the textbox gets focus the backcolor property of the textbox...
4
2875
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty much jsut coping code. I having some issue with...
0
1795
by: Newasps | last post by:
Hi guys, I have a problem with UpdateCommand Event. In tihs event Ä°'m creating required controls to get that controls' values and also get them. But when I try to get updated values I'm getting the...
7
2089
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
2
19813
by: Mamatha | last post by:
Hi I want to add an icon to the textbox's text. I don't know how to display icon in textbox in VB.NET. If any one knows please let me know. Thanks in advance. Mamatha
3
2204
by: Brad Rogers | last post by:
All, Being immersed in vb.net and trying CSharp after almost a year I forgot the differences. I like vb fixing the uppercase/lowercase names and seeming to be more flexible to code entry. ...
2
3002
by: Mike Fox | last post by:
I am trying to implement undo in an application. The problem is the user wants a granular undo like word or studio. Here's the issue: 1. Bring up a record, and edit a field. 2. move to a new...
0
2385
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
8
36862
by: Marco Pais | last post by:
Hi there. How can I change the background color of a textbox when it gets the focus? I can handle the "Enter" event and do this private void txtDummie_Enter(object sender, EventArgs e) { ...
0
829
by: jatin vijay nahar | last post by:
how to undoing in richtextbox in c#.net
0
7136
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
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.