我有以下脚本,用于向 Access 数据库中添加列和表。我不知道如何将该列的“必需”属性设置为“否”,默认值为"is"。这是我的脚本:
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
最佳答案
关于ms-access - 使用 ADOX 在 Access 中添加列时如何设置所需的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7585509/