|
如何在以下函数中添加代码,使得在追加字段的同时,添加“标题”名称,谢谢!
- Sub CreateAccessTable() '创建数据库表
- Dim mycat As New ADOX.Catalog
- Dim myTable As New ADOX.Table
- If Dir(ThisWorkbook.Path & "\database.accdb") = "" Then
- mycat.Create "Provider=Microsoft.ace.OLEDB.12.0;Jet OLEDB:Engine Type=6;" & _
- "Data Source=" & ThisWorkbook.Path & "\database.accdb" '创建数据库
- End If
- mycat.ActiveConnection = "Provider=Microsoft.ace.OLEDB.12.0;Data Source=" & _
- ThisWorkbook.Path & "\database.accdb" '激活连接
- myTable.Name = "测试表a1"
- mycat.Tables.Append myTable '追加表
- With myTable.Columns '追加字段
- .Append "编号", adInteger
- .Append "姓名", adVarWChar, 30
- .Append "出生日期", adDate
- .Append "年龄", adInteger
- .Append "婚姻状况", adBoolean
- End With
- myTable.Keys.Append "PrimaryKey", adKeyPrimary, "编号" '把“编号”字段设为主键
-
- myTable.Columns("姓名").Properties("Jet OLEDB:Allow Zero Length") = True '允许空
-
- mycat.Tables.Refresh '刷新表
- Set myTable = Nothing
- Set mycat.ActiveConnection = Nothing
- End Sub
复制代码
|
|