Programatically setting Required Property in Access 2002 Table

M

Mark H

Hello:

I have a VB 6.0 application where I am able to create my
Access 2000 tables programatically. However I have been
unsuccessful so far in finding out how I can set the
Required property for text columns to NO programatically
when I create the table. I'm using ADOX to create the
table. If you can point me to a KB article that shows
HOWTO I'd be very grateful. Thank you in advance for
your response.
 
G

Guest

Mark,

I had some code to make an Autonumber field, ran through a list properties
to see what was required...
Nullable = False

Steve

See FirstName field below:

Public Sub CreateAutoIncrColumn()

Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim prp As ADOX.Property

' cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
' "Data Source= c:\Program Files\" & _
' "Microsoft Office\Office\Samples\Northwind.mdb;"
' Set cat.ActiveConnection = cnn

Set cat.ActiveConnection = CurrentProject.Connection

With tbl
.NAME = "MyContacts"
Set .ParentCatalog = cat
' Create fields and append them to the new Table object.
.Columns.Append "ContactId", adInteger
' Make the ContactId column and auto incrementing Column
.Columns("ContactId").Properties("AutoIncrement") = True
.Columns.Append "CustomerID", adVarWChar

.Columns.Append "FirstName", adVarWChar
.Columns("FirstName").Properties("Nullable") = False
' For Each prp In .Columns("FirstName").Properties
' Debug.Print prp.NAME, prp.Value
' Next

.Columns.Append "LastName", adVarWChar
.Columns("LastName").Properties("Nullable") = False


.Columns.Append "Phone", adVarWChar, 20
.Columns.Append "Notes", adLongVarWChar
End With

'Append new table
cat.Tables.Append tbl

Set tbl = Nothing
Set cat = Nothing
Set cnn = Nothing

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