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?
11 2265
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.
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?
A quick and easy way is some code in the Form's BeforeUpdate event. - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
On Error GoTo ErrorHandler
-
If (Not ( IsNull ( [Enrollment Date] ) ) ) And ( IsNull(count) ) Then
-
Cancel = True
-
MsgBox "Count is required if an Enrollment Date is entered."
-
End If
-
ExitCode:
-
Exit Sub
-
ErrorHandler:
-
MsgBox Err.number & " - " & Err.Description
-
Resume ExitCode
-
End Sub
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!
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.
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
regarding form validation, will a seperate message box come up with each error type? thanks!
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: - If (logic for checking that your rule was broken) Then
-
MsgBox "your message to the user"
-
Cancel = True
-
End If
And you can do a bunch of those one after another.
brilliant! thank you again.
Todd
No problem, Todd. Good luck.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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,...
| |