View Full Version : Validation Rule for Number Field


Brian25
04-17-2001, 07:44 AM
Hi -

I'm setting up an equipment database in which we're storing HVAC information for different locations. When the data is entered, each piece of equipment is assigned to a location code and given an identitfier (autonumber). Since each location can have multiple pieces of equipment, we're also labeling HVAC units 1, 2, 3, etc. I need to make sure that each location doesn't have duplicate unit numbers (for example, location 0001 has 3 HVAC units, all entered by different people. I need to make sure they're labeled "Unit 1", "Unit 2", "Unit 3", and not all entered as "Unit 1"). If possible, I'd like Access to automatically select the unit # for them so that the first record entered for a location would be unit 1, the second would be unit 2, etc. Any help would be greatly appreciated.

Thanks in advance,
Brian

charityg
04-17-2001, 08:59 AM
Create a recordset based on the table containing the location field. After the update of the locations field use this code:
dim unit as integer
unit =0
do until rst.eof
if rst!location = me!location then
unit=unit+1
endif
loop
me!unitfield=unit

This code should loop through the table to find any entries for the current location and then add 1 to unit for each entry it finds.