Setting the same validation rule on multiple fields

  • Thread starter Thread starter Oisin
  • Start date Start date
O

Oisin

I want to set a validation rule for multiple fields in a table at the same
time in the design view. For example, set the validation rule ">=0" for all
fields whose type is Number in a table.

I can of course just set the validation rule for each field seperately but
this is tedious when there are many fields.

I am using Access 97.

Your help is appreciated,
Oisin.
 
There's no way that I'm aware of to do this through the GUI. You can,
however, set the validation rules through VBA. Something like the following
untested aircode will go through all tables in the database and set all
Integers or Long Integers to have a validation rule of >0

Dim dbCurr As Database
Dim tdfCurr As TableDef
Dim fldCurr As Field

Set dbCurr = CurrentDb()
For Each tdfCurr In dbCurr.TableDefs
If (tdfCurr.Attributes And dbSystemObject) = 0 And _
(tdfCurr.Attributes And dbAttachedTable) = 0 Then
For Each fldCurr In tdfCurr.Fields
If fldCurr.Type = dbInteger Or fldCurr.Type = dbLong
fldCurr.ValidationRule = ">0"
End If
Next fldCurr
End If
Next tdfCurr
 
Back
Top