Solved

Validating one field based on another in the same record

Posted on 2011-03-15
3
197 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now