Modify tables design with code

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I have a form that creates a table when a button on it is
pushed. I would like to be able to limit the number of
records to 14. I figured I could use a validation rule on
an ID column. How can I add the validation rule using
code? Thanks.
 
The following code assumes that the table lives in the same MDB as the code.
If the table is a linked table, you'll need to use OpenDatabase instead of
CurrentDb to get a reference to the database that contains the table.

Public Sub ValRule()

Dim db As DAO.Database
Dim tdf As DAO.TableDef

Set db = CurrentDb
Set tdf = db.TableDefs("Table1")
tdf.Properties("ValidationRule") = "TestID <= 14"
tdf.Properties("ValidationText") = "No more records can be added to this
table."

End Sub
 
Back
Top