473,804 Members | 3,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data entry validation

5 New Member
Hi every body,

I have some basic queries regarding validation of data entered by different users:

I have a form from where the users are going to enter the data. I have tried to put some validation rule for the data entered and I am checking at the EXIT procedure of the objects. With this, whenever an incorrect data is entered a message pops up and the focus is set to the text box again for another entry. This thing works ok but I want to set such rules for many data entry boxes. If I put in all of these codes on EXIT procedures, some times some of these rules do not work. I was surprised to note that if I change the procedure to private and vice-versa it starts working again.
Any suggestions for a better way to deal with this?

Also, if the data entry is done directly from the table, it does not look at the rules. How should this type of validation be done?
Aug 22 '06 #1
5 5518
comteck
179 New Member
You can set validation rules for all forms, or for individual forms. I'm not sure that you can do it for a select number of forms.

comteck
Aug 22 '06 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
I interpret from your message that you are validating entry using VBA code in the On Exit events of fields.

Does this have to be done each time. I would normally put all validation into a Function. The function can then be called from the Save button of a form.

As long as a Function is written in the class (VBA code) of the form it can be called anywhere on the form and can use the values in any field on the form using the Me.Field.Value

For example:

Function Validation() As Boolean

' Initialise Validation Return
Validation = True

' Enter all your validation code here

' If at any time validation rules have been broken set the following
Validation = False

' Add a message box and reset the appropriate field value

' When the funtion ends it will return a True or False value

End Function


See the following procedure as an example of calling the function.

Private Sub cmdSave_Click(C ancel As Integer)
Dim rslt as Boolean

rslt = Validation
If rslt = True Then
' Your code, e.g. close the form
Else
'Return to the form
Me.SetFocus

End Sub


Hi every body,

I have some basic queries regarding validation of data entered by different users:

I have a form from where the users are going to enter the data. I have tried to put some validation rule for the data entered and I am checking at the EXIT procedure of the objects. With this, whenever an incorrect data is entered a message pops up and the focus is set to the text box again for another entry. This thing works ok but I want to set such rules for many data entry boxes. If I put in all of these codes on EXIT procedures, some times some of these rules do not work. I was surprised to note that if I change the procedure to private and vice-versa it starts working again.
Any suggestions for a better way to deal with this?

Also, if the data entry is done directly from the table, it does not look at the rules. How should this type of validation be done?
Aug 22 '06 #3
peev2001
5 New Member
Thanks for your prompt replies. I am going to try writing these rules to a function and then checking on a save event. But actually, my requirement is to validate the data as and when it is entered. E.g if a wrong data is entered, I want a message to pop up and not accept the data entered and bring focus back to that field and ask for a correct entry. I want to do this for several fields.
Following is the script that I have now. I have a similar script for 6 fields e.g. and some of the validation rules do not work every time.
---------------------------------
Sub CL_path_Exit(Ca ncel As Integer)
Me.CL_modified_ new_CL.SetFocus
If (CL_modified_ne w_CL.Text = "YES") And IsNull(Me.CL_pa th) = True Then
MsgBox "You must enter CL path."
'Me.CL_path.Set Focus
Else
If (CL_modified_ne w_CL.Text = "NO CHANGE") And Not IsNull(Me.CL_pa th) = True Then
MsgBox "CL path should be blank."
Exit Sub
End If
End If
If (CL_modified_ne w_CL.Text = "YES") And IsNull(Me.CL_pa th) = True Or (CL_modified_ne w_CL.Text = "NO CHANGE") And Not IsNull(Me.CL_pa th) = True Then
Me.CL_path.SetF ocus
Else
Me.Tuning_param eters_changed.S etFocus
End If
End Sub
--------------------------------------------------
Aug 23 '06 #4
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try this code instead.

Firstly, the '= True' at the end of an IsNull statement is not required.
Secondly, you haven't got the logic right on your last if statement you have to bracket both sides off. However, I think the reworking I've done on the logic will capture all events and eliminate the problems you've been having.

Sub CL_path_exit(Ca ncel As Integer)

Me.CL_modified_ new_CL.SetFocus
If (CL_modified_ne w_CL.Text = "YES") And IsNull(Me.CL_pa th) Then
MsgBox "You must enter CL path."
Me.CL_path.SetF ocus
ElseIf (CL_modified_ne w_CL.Text = "NO CHANGE") And Not IsNull(Me.CL_pa th) Then
MsgBox "CL path should be blank."
Me.CL_path.SetF ocus
Exit Sub
Else
Me.Tuning_param eters_changed.S etFocus
End If

End Sub

If you want to change this to a function you can pass all three parameters in as strings.


Thanks for your prompt replies. I am going to try writing these rules to a function and then checking on a save event. But actually, my requirement is to validate the data as and when it is entered. E.g if a wrong data is entered, I want a message to pop up and not accept the data entered and bring focus back to that field and ask for a correct entry. I want to do this for several fields.
Following is the script that I have now. I have a similar script for 6 fields e.g. and some of the validation rules do not work every time.
---------------------------------
Sub CL_path_Exit(Ca ncel As Integer)
Me.CL_modified_ new_CL.SetFocus
If (CL_modified_ne w_CL.Text = "YES") And IsNull(Me.CL_pa th) = True Then
MsgBox "You must enter CL path."
'Me.CL_path.Set Focus
Else
If (CL_modified_ne w_CL.Text = "NO CHANGE") And Not IsNull(Me.CL_pa th) = True Then
MsgBox "CL path should be blank."
Exit Sub
End If
End If
If (CL_modified_ne w_CL.Text = "YES") And IsNull(Me.CL_pa th) = True Or (CL_modified_ne w_CL.Text = "NO CHANGE") And Not IsNull(Me.CL_pa th) = True Then
Me.CL_path.SetF ocus
Else
Me.Tuning_param eters_changed.S etFocus
End If
End Sub
--------------------------------------------------
Aug 23 '06 #5
peev2001
5 New Member
Great!!Thanks, I will try this tonight.
Aug 24 '06 #6

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

Similar topics

5
10954
by: Otto Krüse | last post by:
Hi everyone, I'm building a GUI in which I want, amongst other things, for people to fill in there postal code. The postal codes of my country (Holland) are in this format: 1234 AB So for the input I use two entry widgets, one of a length of (characters) for the numbers and one of lenght 2 for the letters. What I don't like is that although the visible part of the widgets thus are 4 and 2 characters, users can actually input more...
1
2372
by: Bill nguyen | last post by:
I use the sub below to detect data entry error. The problem is that users are still able to move out of the textbox AFTER the sub is run (and error msg popped up) without having to correct the invalid data. In order to trap all possible movements, I have to run the sub in Key events and Mouse events. This is a lot of work. I guess there must be a way to catch all key/mouse in and out the text box so that we can run validation once and...
3
4965
by: Furty | last post by:
Hi, I'm looking for the best practice for creating a generic data validation implementation for my data bound business objects. I currently have a business object base class implementing the following interfaces: IEditableObject, ICloneable, INotifyPropertyChanged, and IDataErrorInfo More specifically, my IDataErrorInfo implementation is like so:
9
3140
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to be inserted into a standard web address in the table (the filed name is link) in ddw1 Example address ---
12
1450
by: tanhaa | last post by:
Hi all, Just curious if Javascript can do this for me: I have data stored in a particular format and when displaying that data, I want it to be shown in specific format. E.G. Phone numbers: the numbers are stored in a string format: 3335551212
4
2915
by: sanou | last post by:
Hi No doubt this question, or a similar version of it, has been asked before. But, I was looking around the forums and i couldn't find anything. I'm using VC++ to create a simple calculator that sums the values from 2 textboxes. I wanted to implement a simple data validation that would spit out various error messages if the user typed in incorrect data. I managed to vomit out the following code. Yes I know it's beastly,...
3
1688
by: Fanyang | last post by:
Hi, I am new to SQL. I am building a form to do data entry. I have some questions in the questionnaire like: a). are you qualified? b). if you are qualified, which level? I want to restrict the data entry for question b only when answer in question a is "Yes".
20
6934
by: hippomedon | last post by:
Hello everyone, I'm looking for some advice on whether I should break the normalization rule. Normally, I would not consider it, but this seems to be a special case. I have created an "Outcomes Database" used to store response data from measures/ questionnaires for a longitudinal health study. It is essentially derived from Duane Hookom's Survey Database (thanks Duane!!!), with many modifications added to fit the needs of my lab.
18
2415
vikas251074
by: vikas251074 | last post by:
I am using ASP In my company, all employees have to sent materials out of premises. Any employee who need to sent material out will use this web application. In the first page, an employee enters firm name, vehicle no, driver name, purpose, persons taking out, received by, remarks. In the second page, employee enters no. of materials to be taken out. In the third page, displays no. of rows for entry of material details like material name,...
0
9585
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,...
0
10586
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
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
6856
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
5525
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
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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
3
2997
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.