473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Table validation rule based on another record

2
Hi, I am constructing a database to control vehicles. In one of the tables I want to insert every week the odometer of every vehicle. Like this:
Field 1: ID Autonumber
Field 2: VehicleNumber (related to another table with all the vehicles)
Field 3: Date
Field 4: Odometer

When introducing a value in Field 4 (odometer value), I would like to check for the past records and see what was the last value in this field for the same VehicleNumber, and restrict the value to be higher than the last one.

Is this possible? Or do I need to look for another arrange?

Help appreciated...

Thanks
Sep 15 '15 #1
5 3619
MikeTheBike
639 Expert 512MB
Hi
On the basis that this will be entered on a form, you could use a domain function to find the highest previous reading for a given VehicleNumber in the Control/Form BeforeUpdate event and act as appropriate for the milage enterd.

ie.
Expand|Select|Wrap|Line Numbers
  1. VMax("Odometer",""YourTableName","VehicleNumber = " & me.Odometer)
This assumes there is a control on the form call Odometer and it is a numeric field in the table.

HTH


MTB
Sep 15 '15 #2
sershh
2
Hi, is there any way to make this validation in the same table? Or it is forced to be in a form?

Thank you!!
Sep 15 '15 #3
MikeTheBike
639 Expert 512MB
As fare as I am aware this cannot be done in table design. The functions that are available to used do not include the Domain function it would seem.


MTB
Sep 16 '15 #4
Rabbit
12,516 Expert Mod 8TB
Depending on what version of Access you have, specifically 2010 onwards, you might be able to use data macros to do that validation.
Sep 16 '15 #5
ADezii
8,834 Expert 8TB
  1. As indicated by Rabbit, You can use a Data Macro for this Validation.
  2. Assuming your Table is named _tblTest, the [Odometer] Field is LONG, and [VehicleNumber] is TEXT.
  3. Open _tblTest, click Table Tab.
  4. Select Before Change Event of the Table.
  5. Select the If...Then Construct as an Action.
  6. For the If part:
    Expand|Select|Wrap|Line Numbers
    1. [Odometer]<=DMax("[Odometer]","_tblTest","[VehicleNumber]='" & [VehicleNumber] & "'")
  7. For the Then part:
    RaiseError with a Numeric Value and Description.
  8. Select StopMacro as an additional Action.
  9. Hope this helps.
Sep 17 '15 #6

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

Similar topics

2
by: Dalan | last post by:
This ought to be simple enough, but not certain which to use. I have a few fields set to Require data to be entered; however, the message displayed by Access 97 is too generic to be of any real...
2
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one...
0
by: Steve V | last post by:
I'm using Access 2000 to build a budgeting/tracking database. Can I make a validation rule (using VBA) that checks the data as if the record has already been added? I've got 5 tables (only the...
6
by: Chuck | last post by:
A97. A database has a table: tblA which has a single text field, B. It is a primary field, indexed and no duplicates. It is used as a lookup for table tblC. A form based on tblA is used to add...
4
by: ron | last post by:
I have a access based guest book. I want to create a validation rule to block certain words or parts of a srting. How do i do this? ie: this is a nice site. come visit my porn site at www.abc.zy...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
1
by: MLH | last post by:
Anyone remember if A97 append query failure would ever report data breaking validation rule when such was not the case. I have an old SQL statement - several years old now. I've encountered a case...
0
by: Rod Faulk | last post by:
Hi! I have a problem almost exactly like this one: http://bytes.com/topic/access/answers/870079-updating-pivot-table-page-fields-based-another-page-field Nevermind.
13
by: DavidAustin | last post by:
Hi there. I have made a database which has a table with validation rules attached to each of the fields in order to prevent "bad data". For example the forename must be included in the table so I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.