programmatically setting validation rules

D

Demyan

Hi,
Could you please suggest me a way to set validation rules programmatically,
rather than manually, opening a table in 'Design' view and setting
'Validation rule' property for each data column?
Thank you very much!
 
D

Demyan

Allen, when I try to run the following simple code - I go through variables
have in the database, and set for some of them a 1-to-5 value range -

Option Compare Database
Sub DimaTest()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb
For Each tdf In db.TableDefs
For Each fld In tdf.Fields
fName = Mid(fld.Name, 2, 4)
If fName = "data" Or fName = "dyta" Then
fld.ValidationRule = "BETWEEN 1 AND 5"
End If
Next
Next
End Sub

I get error message 'Property value is too large', with validation-rule
highlighted. Can you tell me what's wrong?
Thank you very much.
 
D

Demyan

Hi, Allen,
No, my database is small, and field names short. But I accidentally solved
the problem, whatever it was, by re-typing 'BETWEEN' without caps! :)
Thank you so much for help!
 
A

Allen Browne

Really? What version?

(I tried it in A2003, using caps. It accepted the entry, but converted to
proper case in the rule.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top