.mdb.access数据库VBA-利用Access对象在已有的数据库中创建数据表 |
时间:2025-01-20 08:52:44 来源: 作者: |
利用Access对象在已有的数据库中创建数据表 eJz检测VBA 代码:与1-8不同处加注释,其它相同eJz检测VBA Public Sub1_9()eJz检测VBA Dim appAccess As Access.ApplicationeJz检测VBA Dim dbs As ObjecteJz检测VBA Dim myTbl As ObjecteJz检测VBA Dim myFld As VarianteJz检测VBA Dim myData As StringeJz检测VBA Dim myTable As StringeJz检测VBA myData = ThisWorkbook.Path & "\学生成绩管理.mdb"eJz检测VBA myTable = "期末成绩"eJz检测VBA Set appAccess = New Access.ApplicationeJz检测VBA ‘打开一个现有的Access数据库eJz检测VBA appAccess.OpenCurrentDatabase myDataeJz检测VBA Set dbs = appAccess.CurrentDbeJz检测VBA ‘删除数据库中已经存在的同名数据表eJz检测VBA dbs.TableDefs.Delete myTableeJz检测VBA Set myTbl = dbs.CreateTableDef(myTable)eJz检测VBA Set myFld = myTbl.CreateField("学号", DB_Text, 10)eJz检测VBA myTbl.Fields.Append myFldeJz检测VBA Set myFld = myTbl.CreateField("姓名", DB_Text, 6)eJz检测VBA myTbl.Fields.Append myFldeJz检测VBA Set myFld = myTbl.CreateField("性别", DB_Text, 1)eJz检测VBA myTbl.Fields.Append myFldeJz检测VBA Set myFld = myTbl.CreateField("班级", DB_Text, 10)eJz检测VBA myTbl.Fields.Append myFldeJz检测VBA Set myFld = myTbl.CreateField("数学", DB_SINGLE)eJz检测VBA myTbl.Fields.Append myFldeJz检测VBA Set myFld = myTbl.CreateField("语文", DB_SINGLE)eJz检测VBA myTbl.Fields.Append myFldeJz检测VBA Set myFld = myTbl.CreateField("物理", DB_SINGLE)eJz检测VBA myTbl.Fields.Append myFldeJz检测VBA Set myFld = myTbl.CreateField("化学", DB_SINGLE)eJz检测VBA myTbl.Fields.Append myFldeJz检测VBA Set myFld = myTbl.CreateField("英语", DB_SINGLE)eJz检测VBA myTbl.Fields.Append myFldeJz检测VBA Set myFld = myTbl.CreateField("总分", DB_SINGLE)eJz检测VBA myTbl.Fields.Append myFldeJz检测VBA dbs.TableDefs.Append myTbleJz检测VBA appAccess.QuiteJz检测VBA Set appAccess = NothingeJz检测VBA Set dbs = NothingeJz检测VBA Set myTbl = NothingeJz检测VBA Set myFld = NothingeJz检测VBA MsgBox "数据表<" & myTable & ">创建成功!", _eJz检测VBA vbOKOnly + vbInformation, "创建数据表"eJz检测VBA End SubeJz检测VBA
扩展:appaccess.opencurrentdatabase mydata, ,”12345” ‘打开带有密码的数据表eJz检测VBA |
|
|
|