473,664 Members | 3,028 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 1127
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
2359
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 client-side Javascript validation which flags up when a field is empty but the form is still submitted. Here is the ASP code I am using to submit the form to an e- mail with CDONTS:
3
13999
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 dosent meet these requirments an error message will be displayed. I have pasted the code (and highlighted the relevant parts) below in the hope that someone can help me out with this. Ive been trying to suss it out all week & it's driving me nuts!...
4
2886
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 Javascript before submission. I've set out the part of the validation script used to loop through the dynamically generated fields below. This is where I am encountering
2
4931
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 his or her changes in the box and restore the previous value if he or she is not allowed (or not let the value be changed in the first place).
0
2432
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 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that article and recreated the situation I see in my application. (Code included below.) If you run the...
16
5500
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 validating event. Am I doing something wrong here? Thanks Al Imports system
0
1218
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 boxes, combo boxes, and checkboxes.) The Footer section contains nothing. This subform is shown in "continuous forms" mode, showing several rows
2
2678
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 how can i tell that those events have finished so that i can test for a new situation. My problem is i am modding some existing code, were the TAB key keypress is captured by a external c# module.
0
8437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5660
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2764
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 we have to send another system
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1759
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.