473,506 Members | 13,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating changes to a form field

12 New Member
I would like to be able to enter a value into a field that currently is in a null state without initiating an event but once a value has been assigned to that field that further changes will initiate an event that opens a message box that prompt the user to decide if they want to save the changes or not. Can someone help me with this?
Dec 9 '07 #1
2 1118
missinglinq
3,532 Recognized Expert Specialist
This code will throw up a messagebox asking the user if they want to keep the info already input. If they answer Yes the cursor moves to the next field, if they answer No, the cursor returns to the field in question and the data is hilighted, ready to be replaced or simply deleted.

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextBox_BeforeUpdate(Cancel As Integer)
  2. If MsgBox("Are You Sure You Want To Keep   " & Me.YourTextBox & "   In This Field?", vbYesNo) = vbNo Then
  3.  Cancel = True
  4.  Me.YourTextBox.SelStart = 0
  5.  Me.YourTextBox.SelLength = Len(Me.YourTextBox)
  6. End If
  7. End Sub
Welcome to TheScripts!

Linq ;0)>
Dec 9 '07 #2
Lykus
12 New Member
Thank you, missinglinq! This works great, however, I need to be able to circumvent the message box prompt if it is a new record. Someone just informed me that I could use the NewRecord property to do this. The code I was given looks something like this (the control in my example below is dtmDateAssnd):
Expand|Select|Wrap|Line Numbers
  1. Private Sub dtmDateAssnd_BeforeUpdate(Cancel As Integer)
  2.  
  3.         Dim strMsg As String
  4.         Dim iResponse As Integer
  5.  
  6.         If Not (Me.NewRecord) Then  
  7.  
  8.         ' Specify the message to display.
  9.         strMsg = "Do you wish to save the changes?" & Chr(10)
  10.         strMsg = strMsg & "Click Yes to Save or No to Discard changes."
  11.  
  12.         ' Display the message box.
  13.         iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?")
  14.  
  15.         ' Check the user's response.
  16.         If iResponse = vbNo Then
  17.             ' Undo the change.
  18.             Me!dtmDateAssnd.Undo
  19.  
  20.             ' Cancel the update.
  21.             Cancel = True
  22.         End If
  23.         End If
  24.  
  25.      End Sub
Dec 10 '07 #3

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

Similar topics

4
2352
by: Andrew Williams | last post by:
Does anyone know of a way to quickly validate an HTML web form? I need to make sure that certain fields on my form actually contain data and are not submitted blank. I have tried using...
3
13984
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it...
4
2865
by: EmmettPower | last post by:
Hi, I have a form which includes a field 'number'. When 'number' is changed additional fields ('item_0', etc) are generated on the form using 'onchange'. I want to validate the form using...
2
4904
by: Ken Loomis | last post by:
Hello: Using WinForms, certain users may change the value in a combobox, others may not. Some of these boxes open with a default value. I need to check the user's rights before committing...
0
2423
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
16
5484
by: Al Santino | last post by:
Hi, It appears displaying a messagebox in a validating event will cancel the subsequent event. In the program below, button 2's click event doesn't fire if you open a dialog box in button 1's...
0
1212
by: RLN | last post by:
Hello.... I have a subform with a header, detail and form footer. The form Header contains labels identifying the fields in the detail row. The Detail section contains 10 data fields (text...
2
2665
by: Peted | last post by:
Hi if i derive a reference to a control on a winform (ie Control activeControl = somecontrol on the form) how can i test if that control has a validating or validated event and more importantly...
0
7220
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
7308
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
7479
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
5617
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,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
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
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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
757
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.