Solved

Validating one field based on another in the same record

Posted on 2011-03-15
3
200 Views
Last Modified: 2012-08-14
My database tracks barrel racing events.  There is an event table with one record for each event and a class table that contains a record for each class in each event.  I have a form, Add/Update Events, which contains event information on the main form and a datasheet view of class records related to the event currently displayed. In the class table I have many fields which contain information relevant to the class but for purposes of this question, the class table has these fields: EventID, ClassType (text), IncentiveOnly (yes/no), RollFromClass (text).  The field, RollFromClass, should be left null unless IncentiveOnly is set to yes.  In that case, RollFromClass should be assigned a value. That value should only be one of the values previously assigned to ClassType for a class in the current event.

There are 2 data validation issues I am not sure how to handle.  The first is to ensure that RollFromClass is initialized when IncentiveOnly equals yes.  The second is how to ensure that RollFromClass is initialized correctly, i.e., to one of the values previously entered as ClassType for this event.

Should any of this validation be defined at the table level?  Should I handle it all in the form?  I tried writing code to execute "on exit" from the RollFromClass field but I'm not sure I know how to reference specific rows in the datasheet view correctly.  What do you suggest?
0
Comment
Question by:ProgrammingGrandma
  • 2
3 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 35138667
You will have to use vba code in a data entry form for this.

But I don't really understand what you mean by..
"That value should only be one of the values previously assigned to ClassType for a class in the current event."

This sounds like you have to be referring to other records in the table, which is a bit of a pain in itself, but I don't quite get what you would do with the first record  ( and the logic which follows is that that the second record must be the same as the first, the third must also be the same and so on)

0
 

Accepted Solution

by:
ProgrammingGrandma earned 0 total points
ID: 35139239
OK.  I will focus on VBA code in the form.  The form looks something like this:

Event: Winter Race
Date:   Dec 4, 2010

Class Type       Race Format...      Incentive Only?       Roll From Class

Open Poles       3D                          N
Youth Poles       3D                          Y                              Open Poles
Senior Poles      3D                          Y                              Open Poles
Open Barrels     4D                          N
Youth Barrels     4D                          Y                              Open Barrels

All this data is for the same event.  If Incentive Only? is no, there is no value allowed in Roll From Class.  If Incentive Only? is yes, Roll From Class must have a value and it must be one of the classes already defined for this event and therefore, displayed on this form.  (An incentive only class is one where the contestants don't actually make another run, we just roll their times from the open event to the incentive class they entered.)

In my VBA code, how do I address fields in the subform?  If I use me.[Incentive Only], will VBA assume I am referring to the row which currently contains the cursor or do I need to address the row more specifically?  I am asking because using me.[Incentive Only] in my code is getting inconsistent results.

Secondly, if I do want the user to enter a value in Roll From Class, can I dynamically create a combo box which includes the values currently on the form in the column Class Type?
0
 

Author Closing Comment

by:ProgrammingGrandma
ID: 35225387
My issue is not resolved.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question