473,785 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation Code - Comparing 2 fields on a form

17 New Member
Hello!

Would be grateful for help with this one - a Record level Validation problem
I run Access 2000 on XP

A form has two fields:
1) fldLevel – it’s an Option Group with 4 choices = 1, 2, 3 and 0.
2) fldStatus – is a limited value-list (Combo) with 3 choices = Unassigned, In-Progress, Complete.

Any record in the form cannot be both Level_0 and Status_Complete

Scenario:
A record in the form has been (legally) set to Level_3 and Status_Complete .
For whatever reason, UserX has come in and tried to change the level to 0 (while the status remains as Complete). So, I want to

a) Prevent UserX’s action from being accepted
b) Revert fldLevel back to what it was before UserX attempted the action…….

I have this code which works fine for what I want – up to the point, that at the end of the code the focus is on Level 0, waiting for UserX to change it (s/he could now legally choose to make it Level 1, 2 or 3) but…and this is really my problem: I want the fldLevel focus to be moved back (revert to) to the Level3 it was on before User X tried the illegal change. How can I (or can I?) amend the code to do that?

Private Sub grpLevel_Before Update(Cancel As Integer)
If (Me![fldLevel]) = "0" And (Me![fldStatus]) = "Complete" Then
MsgBox "Your change is not accepted." & vbCrLf & _
"Level cannot be set to 0 if record is at Status 'Complete'. ", _
"Complete Status requires Level to be 1, 2 or 3 only ", _
vbOKOnly, " Level Invalid for Complete Status"
Cancel = True
End If
End Sub

Thanks for any help!
Regards, AMBLY
Jun 9 '07 #1
2 2727
ADezii
8,834 Recognized Expert Expert
Hello!

Would be grateful for help with this one - a Record level Validation problem
I run Access 2000 on XP

A form has two fields:
1) fldLevel – it’s an Option Group with 4 choices = 1, 2, 3 and 0.
2) fldStatus – is a limited value-list (Combo) with 3 choices = Unassigned, In-Progress, Complete.

Any record in the form cannot be both Level_0 and Status_Complete

Scenario:
A record in the form has been (legally) set to Level_3 and Status_Complete .
For whatever reason, UserX has come in and tried to change the level to 0 (while the status remains as Complete). So, I want to

a) Prevent UserX’s action from being accepted
b) Revert fldLevel back to what it was before UserX attempted the action…….

I have this code which works fine for what I want – up to the point, that at the end of the code the focus is on Level 0, waiting for UserX to change it (s/he could now legally choose to make it Level 1, 2 or 3) but…and this is really my problem: I want the fldLevel focus to be moved back (revert to) to the Level3 it was on before User X tried the illegal change. How can I (or can I?) amend the code to do that?

Private Sub grpLevel_Before Update(Cancel As Integer)
If (Me![fldLevel]) = "0" And (Me![fldStatus]) = "Complete" Then
MsgBox "Your change is not accepted." & vbCrLf & _
"Level cannot be set to 0 if record is at Status 'Complete'. ", _
"Complete Status requires Level to be 1, 2 or 3 only ", _
vbOKOnly, " Level Invalid for Complete Status"
Cancel = True
End If
End Sub

Thanks for any help!
Regards, AMBLY
You can prevent this situation before it ever occurs by setting the following Table Validation Rule:
Expand|Select|Wrap|Line Numbers
  1. Not ([Level]=0 And [Status]="Complete")
This will allow every combination of Level and Status 'except' [Level]=0 AND [Status]=Complete
Jun 10 '07 #2
AMBLY
17 New Member
Thankyou ADezii ,
I appreciate your help :-)

I actually have more than one Validation, which applies to the table fields - so I think keeping the Validation at form level works best? In did try this out though, just on the one field as you suggested and it didn't work for me? Maybe I did something wrong....

But anyway, you did set me thinking, and I have now basically put all field Validations at record level in BeforeUpdate, and have added code to lock any record once it is put to Status Completed. Seems to do the trick!

Cheers
AMBLY
Jun 12 '07 #3

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

Similar topics

72
5241
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to complete in connection with attendance at a seminar. After spending more than 15 minutes on it, I clicked on the submit button - and nothing happened. Looking round the pages on Javascript form validation that Google produced for me (well,...
4
2653
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the validation procedure.
5
2610
by: EviL KerneL | last post by:
Hi - I am trying to figure out a way to enforce the validation included for this form based on whether the user chooses "email" or "phone" as the contact choice. Right now it is set to enforce validation on both. Is there a way to link the drop-down choice to the correspondent validation section while disabling validation for the other one? here's what I presently have:
6
5034
by: tm | last post by:
I am trying to reference a table entry (qtyonhand) populated from a recordset. There is only one record displayed on this table. When i try to compare this displayed field to an input field (orderqty) i get an (error on this page or no result at all ). When just comparing the input field to a set of "" everything works fine. This is an ASP file with a javascript function. Thanks in advance. Signed... New at this! code below...
16
2252
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate individual fields, such as an "Email Validation Script" or a "Phone Validation Script". Is it ok to put all these scripts on page as they are or should they be joined in some way together to be one script? I'm a total JavaScript newbie and am completely...
3
6339
by: Bob Alston | last post by:
I have a routine to copy data to new versions of my app via insert into sql statements. Unfortunately, due to evolution of my app, sometimes the new version has more restrictive editing than an older version that I am updating. Thus I get this message. It tells me only how many records have errors, not which errors or which records. Anyone have a nice solution to identifying the specific records involved? Maybe even the specific...
9
4180
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
11
3001
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
12
2500
by: Gustaf | last post by:
I've been working on a membership form for a while, and find it very tedious to get an acceptable level of form validation. A web search for solutions revealed some home-brewed solutions, such as these: http://simonwillison.net/2003/Jun/17/theHolyGrail/ http://samuelsjoberg.com/archive/2004/11/form-validation-on-client-and-server Quoting from the first link, this is my idea of what form validation is like from the user's perspective:
0
9646
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
10350
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
10157
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
10097
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
8983
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
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
5386
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
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2887
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.