Discussion Locked

Access97 Validation dependent on other r

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need to validate an entry depending upon values in another record. In detail a record has a composite PK consisting of a CodeNumber and a Letter (only A,B or C). Valid entries are for example:
CodeNumber Letter
1234 A
1234 B

OR

1234 C

but no other combination of use of the Letters.

I reckon I need some sort of trigger on insert on the table, but Access does have that facility.

Any suggestions will be greatly received.

John

8 replies

by shmaltz

I dont fully understand your question but from what you describe you will have to use a form to enter the data and use VBA on the form to validate the data entered.

by j

thank you newyorker211@yahoo.com

but I am looking for an all encompassing solution that will enable me to avoid having code in all the forms which have access to changing the data - perhaps you will tell me that that is just impossible (or that aPublic Function will cope with each covering each of the forms in one go!)- certainly normal validation and Table Level Validation will not work!

I'd appreciate any further comment.

thanks

john

by mbarker734

The validation rule available in table design will limit the text inserted into a specific field. For your example text the rule would appear as:

Like "1234 A" or Like "1234 B" or Like "1234 C"

This will limit the entries to only those three that are acceptable. This is however very restrictive and will not allow anything but a valid entry once anydata has been entered on the form. Should you not know what the valid entry data the form will produce an error message until the data is input correctly. You can then provide an example of the acceptable data by using the validation text area, the text entered here will be shown upon an invalide entry for the field.

You can close the form if you do not know the correct entry but this will inturn cause all entries for that record active on the form to be lost.

I would advise you develope a drop down or combo box to select the data from on a form. This will insure the entry is correct. I know you do not want to code the forms but it is effiecient for the person entering the data.

Good Luck,

Mark

by j

Thanks Mark for seeking to help,
To clarify the question further the numeric part is in a separate field from the letters.
I think what I am looking for is a categorical statement, one way or the other, about the existance of table level events (atrigger in Sybase parlance). If you (or any one else) can help I will be most pleased - and finally I can close this question!

john

by glen_mcleod

You want to be able to verify that values entered in the 2 PK fields don't conflict with existing records? Can't do it without looking in the table or a cached recordset once the user has entered data in your text boxes. The first involves a tableaccess, but could be fairly quick, as you're working with the PK. The second invlolves keeping records in memory and could seriously impact performance.

I would try the insert and trap on the "Cannot insert duplicate PK" error (can't remember the exact number).

Even if Access offered the equivalent of Triggers, you'd still have to trap for the error, because if the trigger refuses the insert, the user has to be informed.

Glen

by glen_mcleod

Just to add to the last paragraph: I don't think there's a way around adding code to you forms.

by j

Glen,

Thanks
I reckon I have exhausted the possibilities now - so you get the prize!

john

This discussion is closed to new replies.