引用:Microsoft ActiveX Data Objects 2.X library1e4检测VBA 代码:1e4检测VBA public sub1_7()1e4检测VBA dim cnn as new adodb.connection ‘定义connection对象变量1e4检测VBA dim rs as new adodb.recordset ‘ 定义Recordset对象变量1e4检测VBA dim mydata as string ‘定义数据库名称变量1e4检测VBA dim mytable as string ‘定义数据表名称变量1e4检测VBA dim sql as string1e4检测VBA 1e4检测VBA ‘设置数据库名称(包括完整路径)1e4检测VBA mydata=thisworkbook.path & “\学生成绩管理.mdb”1e4检测VBA ‘设置要创建的数据表名称1e4检测VBA mytable=”期末成绩”1e4检测VBA ‘建立与数据库的连接1e4检测VBA with cnn1e4检测VBA .provider=”microsoft.jet.oledb.4.0”1e4检测VBA .open mydata1e4检测VBA end with1e4检测VBA ‘删除数据库中已经存在的数据表1e4检测VBA SQL=”drop table” & mytable1e4检测VBA set rs=cnn.execute(sql)1e4检测VBA ‘设置创建数据表的SQL语句1e4检测VBA sql=”create table” & mytable _1e4检测VBA & “(学号 text(10),姓名 text(6), 性别 text(1), 班级 text(10),” _1e4检测VBA & “数学 single, 语文 single, 物理 single, 化学 single,” _1e4检测VBA & “英语 single, 总分 single)”1e4检测VBA ‘利用execute方法创建数据表1e4检测VBA set rs=cnn.execute(sql)1e4检测VBA ‘关闭数据库1e4检测VBA cnn.close1e4检测VBA ‘释放变量1e4检测VBA set mycat=nothing1e4检测VBA set rs=nothing1e4检测VBA set cnn=nothing1e4检测VBA ‘弹出信息1e4检测VBA msgbox “数据表<” & mytable & “>创建成功!”, vbinformation,”创建数据表”1e4检测VBA end sub1e4检测VBA