473,398 Members | 2,212 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,398 software developers and data experts.

Data Validation

I am Trying to validate information entered into 4 fields on a form. They can not be empty. If one of the fields is empty then the code should give a message athen stop. If all fields are valid then it should continue. I have listed the code below, can some give direction.
[code]
Private Sub GetProjid_Click()
If Forms![frm_proj log]![site id] = "" Then
MsgBox "You have not selected a Location. " & _
"Please Correct This error and resubmit.", vbOKOnly, "Validation Error"
DoCmd.GoToControl "Forms![frm_proj log]![site id]"
Cancel = 1
End If
If Forms![frm_proj log]![Project Title] = "" Then
MsgBox "You have entered a Project Title. " & _
"Please Correct This error and resubmit.", vbOKOnly, "Validation Error"
DoCmd.GoToControl "Forms![frm_proj log]![Project Title]"
Cancel = 1
End If
If Forms![frm_proj log]![Description] = "" Then
MsgBox "You have not entered a Project Description. " & _
"Please Correct This error and resubmit.", vbOKOnly, "Validation Error"
DoCmd.GoToControl "Forms![frm_proj log]![Description]"
Cancel = 1
End If
If Forms![frm_proj log]![Proj# Sponsor] = "" Then
MsgBox "You have not Entered a Project Sponsor. " & _
"Please Correct This error and resubmit.", vbOKOnly, "Validation Error"
DoCmd.GoToControl "Forms![frm_proj log]![Proj# Sponsor]"
Cancel = 1
End If
Forms![frm_proj log]![Project ID] = Forms![frm_proj log]![site id] & "-" & IIf(Forms![frm_proj log]!mth _
< 10, "0" & Forms![frm_proj log]!mth, Forms![frm_proj log]!mth) & IIf(Forms![frm_proj log]!day _
< 10, "0" & Forms![frm_proj log]!day, Forms![frm_proj log]!day) & Forms![frm_proj log]!year & "-" & IIf(Forms![frm_proj log]![Record # fixed] < 10, "0" & Forms![frm_proj log]![Record # fixed], Forms![frm_proj log]![Record # fixed])
Me!New = "no"

End Sub
[code]
Thanks
Oct 24 '07 #1
1 1953
ADezii
8,834 Expert 8TB
I modified only the relevant (Validation) portion of the code segment which should go in the BeforeUpdate() Event of the Form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me![site id]) Then
  3.   MsgBox "You have not selected a Location. " & _
  4.          "Please Correct This error and resubmit.", vbOKOnly, "Validation Error"
  5.            Me![site id].SetFocus
  6.              Cancel = True
  7. ElseIf IsNull(Me![Project Title]) Then
  8.   MsgBox "You have entered a Project Title. " & _
  9.          "Please Correct This error and resubmit.", vbOKOnly, "Validation Error"
  10.            Me![Project Title].SetFocus
  11.              Cancel = True
  12. ElseIf IsNull(Me![Description]) Then
  13.   MsgBox "You have not entered a Project Description. " & _
  14.          "Please Correct This error and resubmit.", vbOKOnly, "Validation Error"
  15.            Me![Description].SetFocus
  16.              Cancel = True
  17. ElseIf IsNull(Me![Proj# Sponsor]) Then
  18.   MsgBox "You have not Entered a Project Sponsor. " & _
  19.          "Please Correct This error and resubmit.", vbOKOnly, "Validation Error"
  20.            Me![Proj# Sponsor].SetFocus
  21.              Cancel = True
  22. End If
  23.  
  24. 'Drop through and resume Normal processing/Updating here
  25. End Sub
Oct 24 '07 #2

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

Similar topics

2
by: Dnna | last post by:
I have a table which is bound to an Internet Explorer XML data island. I'm using ASP.NET's client-side validators for an input field in the table. The problem is that if the input fields are in...
1
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...
1
by: Niclas | last post by:
Hi, I need to validate some data before it is submitted preferably using any of the validation controls in Visual Studion (2003), but the validation is slightly complex and require converision...
3
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...
17
by: stathis gotsis | last post by:
Hello everyone, I am tying to come up with an elegant way to process some input data that come from a form. When the user hits the 'Submit' button, i want the form to appear again with the...
21
by: gurdz | last post by:
Does anyone know how to perform data validation in C? I have searched google for every possible result, and I either end up with data validation for C++ or nothing at all. I have also searched...
5
by: peev2001 | last post by:
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...
18
by: Joel Hedlund | last post by:
Hi! The question of type checking/enforcing has bothered me for a while, and since this newsgroup has a wealth of competence subscribed to it, I figured this would be a great way of learning...
2
by: Rami | last post by:
I am using an XSD schema to validate an XML document. I want to validate both XML structure and . When I try to validate the document, the validation only checks for things like proper tags, and...
20
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
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...
0
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
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
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...

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.