473,386 Members | 1,832 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,386 software developers and data experts.

building required field logic in a form and corresponding error messages

Hi,

I am building a form and i would like it to have conditional error messages.

For instance, I am creating a Date field. If the date field is populated, I also need Field 2 populated and an error message created. However, if the date field is not populated, then Field 2 need not be populated.

is this possible?
Apr 28 '09 #1
11 2265
ChipR
1,287 Expert 1GB
You could use a form with unbound controls and a Save or Submit button. On click, you can execute whatever validation code you want, then if everything is valid, insert a record. That's my preference for forms with lots of validation, anyway. Let me know if you decide to go this route and have problems.
Apr 28 '09 #2
Hi Chip,

thanks for responding! Here's where i have problems. i'm not sure where to put the logic. the logic i'm hoping to build is something like this:

Expr1: IIf([ENROLLMENT DATE] Is Not Null And [count] Is Null, {REJECT RECORD AND DISPLAY ERROR MESSAGE COUNT REQUIRED},{ACCEPT THE RECORD})

I'm hoping to design the form so that the capitalized and encased in {} is the outcome. does this make sense?
Apr 28 '09 #3
ChipR
1,287 Expert 1GB
A quick and easy way is some code in the Form's BeforeUpdate event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. On Error GoTo ErrorHandler
  3.     If (Not ( IsNull ( [Enrollment Date] ) ) ) And ( IsNull(count) ) Then
  4.         Cancel = True
  5.         MsgBox "Count is required if an Enrollment Date is entered."
  6.     End If
  7. ExitCode:
  8.     Exit Sub
  9. ErrorHandler:
  10.     MsgBox Err.number & " - " & Err.Description
  11. Resume ExitCode
  12. End Sub
Apr 28 '09 #4
Great! what if i have multiple things that i need to check. do i need to fit the logic within one statement or can i create multiple statements. if i can create multiple statements, then will each error message come up seperately?

finally, what's the function of the ErrorHandler? is that for me to create my own error message? confused then about the msgbox "count is required". are those redundant? thanks so much!
Apr 28 '09 #5
ChipR
1,287 Expert 1GB
You can check multiple things with multiple statements, and give an appropriate MsgBox for each. They will all be checked, and then at the end if Cancel was set to True by any of them, the update will cancel, and the record won't be saved.

The error handling code will only be called in case something in your code creates a run-time error, which would normally crash the program. Error handling allows you to display a nice message box and not crash, in case you caused a problem that wasn't caught when you compiled, but it has nothing to do with your validation. Sorry to confuse you with that. It's not really necessary for development, since you can debug, but if you are planning to release your application for others to use, it should be in every piece of code.
Apr 28 '09 #6
thanks Chip, i'll give it a shot! your assistance is very much appreciated. thank you so much!

i'll let you know how it goes. Todd
Apr 28 '09 #7
regarding form validation, will a seperate message box come up with each error type? thanks!
Apr 28 '09 #8
ChipR
1,287 Expert 1GB
Just to be clear, let's not describe them as errors, because there are predefined errors that already exist and have another purpose. For each validation check you want to do, use the format:
Expand|Select|Wrap|Line Numbers
  1.   If (logic for checking that your rule was broken) Then
  2.      MsgBox "your message to the user"
  3.      Cancel = True
  4.   End If
And you can do a bunch of those one after another.
Apr 28 '09 #9
brilliant! thank you again.

Todd
Apr 28 '09 #10
ChipR
1,287 Expert 1GB
No problem, Todd. Good luck.
Apr 28 '09 #11
NeoPa
32,556 Expert Mod 16PB
It's not for everyone, or even every situation (There is only one message for instance), but Access tables include Validation Rule & Validation Text properties. These can be used at a table level (which means they are not reliant on the operator using the intended form) and can specify how the data in the table can fit together.

To be honest, I doubt this will help you with your current problem Todd, but it may help some of those who are looking for similar answers and find this thread.
Apr 29 '09 #12

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

Similar topics

1
by: Melissa | last post by:
I have a web form that has required field validators, and then submits an email when the form is completely filled out. Well, it is working on my local machine, but when I put it out on the server,...
16
by: Georges Heinesch | last post by:
Hi. My form contains a control (cboFooBar), which has an underlying field with the "Required" property set to "Yes". Now, while filling out all the controls of the form, I have to fill out this...
3
by: Mark | last post by:
Access97 --- I set the Required property for a field at the table level and I have a form that contains that field. When I click the Close button at the top left of the screen, I get an error...
13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
1
by: swingingming | last post by:
Hi, I made a form based on one table that has several required fields. If in the form, I leave some of them blank and close the form using 'X', I get 2 warning messages, 1st is "... field is...
0
by: roger23 | last post by:
I get this error C:\Program Files\MSBuild\Microsoft\WebDeployment\v8.0\Microsoft.WebDeployment.targets(526,9): error MSB6006: "aspnet_compiler.exe" exited with code 1. at the end of my build...
1
by: Denis | last post by:
Hi I have a field called firstname in a table called table1. I have it set as required in a form. How do I display a customized error message rather than the standard one given by Access below ...
7
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
1
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.