Create Table statement for fields with validation

S

Sha S

Hello,

I have this statement:

Set dbs = CurrentDb

Set tbl = dbs.CreateTableDef("usrtmptbl_linkedobjs")

With tbl
.Fields.Append .CreateField("uID", dbLong)
.Fields("uID").Attributes = dbAutoIncrField
.Fields.Append .CreateField("build_date", dbDate)
.Fields("build_date").DefaultValue = "Now()"
.Fields.Append .CreateField("uNAME", dbText)
.Fields.Append .CreateField("Local_Flag", dbInteger)
End With

dbs.TableDefs.Append tbl


In the above table, for field "Local_Flag", the values must be one of (0, 1
or Null ).

I would appreciate if someone could suggest how to include that in the above
code.

Thank You,

sHa.
 
M

Marshall Barton

Sha said:
Hello,

I have this statement:

Set dbs = CurrentDb

Set tbl = dbs.CreateTableDef("usrtmptbl_linkedobjs")

With tbl
.Fields.Append .CreateField("uID", dbLong)
.Fields("uID").Attributes = dbAutoIncrField
.Fields.Append .CreateField("build_date", dbDate)
.Fields("build_date").DefaultValue = "Now()"
.Fields.Append .CreateField("uNAME", dbText)
.Fields.Append .CreateField("Local_Flag", dbInteger)
End With

dbs.TableDefs.Append tbl


In the above table, for field "Local_Flag", the values must be one of (0, 1
or Null ).


I think all you need is to replace the line:
.Fields.Append .CreateField("Local_Flag", dbInteger)
with something like:
Set fld = .CreateField("Local_Flag", dbInteger)
fld.ValidationRule = "Is Null Or =0 Or =1"
.Fields.Append fld
 
S

Sha S

Thanks for the reply, JimBurke.

I was thinking of some sort of a validation rule, and how to code it into
the create table routine. Since it is a temp table, figured no harm in
doing it on the table vs on the form. If there is a way to add a validation
rule through the code, any help is appreciated.

Thanks,

Sha.
 

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