Re: Change Field.required property in ADOX

  • Thread starter Brendan Reynolds
  • Start date
B

Brendan Reynolds

There is no "Required" property in ADOX. In ADOX, set the Nullable property
to False to require entry in a field, or True to allow records with no entry
in the field.
 
G

Guest

I'm trying to do the same thing. Can't figure out the syntax

Dim oTbl As ADOX.Table
Set oTbl = New ADOX.Table
'Add field
oTbl.Columns.Append "lngTestValue", adInteger

' this works, but now I want to set the "Nullable" property to true.
'I tried a bunch of things, but can't find the right syntax.
 
B

Brendan Reynolds

Now I remember why I dislike ADOX so much! :-(

On testing, I can't get my original suggestion to work either. But the
following seems to work. After running this code, when I look at the table
in design view, the first field ("ANonNullableColumn") has the Required
property set, the second field ("ANullableColumn") doesn't.

Public Sub TestNullable()

Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim col1 As ADOX.Column
Dim col2 As ADOX.Column

Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables("tblTest")
Set col1 = New ADOX.Column
With col1
.Name = "ANonNullableColumn"
.Type = adInteger
End With
tbl.Columns.Append col1
Set col2 = New ADOX.Column
With col2
.Name = "ANullableColumn"
.Type = adInteger
.Attributes = adColNullable '<------------------------------------NB
End With
tbl.Columns.Append col2

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