Modify tables design with code

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.
 
B

Brendan Reynolds \(MVP\)

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
 

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