我有以下脚本在Access数据库中添加列和表。我不知道如何将该列的“required”属性设置为“NO”,默认为yes。这是我的剧本:
Option Compare Database
Function AddColumns()
'Purpose: Show how to add fields to a table, and delete them using ADOX.
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim col As New ADOX.Column
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=\\network\drive\TestDB.accdb; Jet OLEDB:Database Password=testing; "
'Initialize
cat.ActiveConnection = cnn
Set tbl = cat.Tables("Test_Table")
'Add a new column
With col
.Name = "Test_Column"
.Type = adVarWChar 'Decimal type.
'.Precision = 28 '28 digits.
'.NumericScale = 8 '8 decimal places.
End With
tbl.Columns.Append col
MsgBox col.Name & " successfully added"
Set col = Nothing
'Debug.Print "Column added."
'Clean up
Set col = Nothing
Set tbl = Nothing
Set cat = Nothing
End Function
答案 0 :(得分:2)