VB中代码创建数据库
首先引用Mcrsoft DAO 3.6(或2.5或3.51)对象库和Mcrsoft Access 9.0对象库,在表单中添加Command1,粘贴以下代码:
private Sub command 1 _ Click()
Dim wrk default As Workspace
Dim DBS new As Database
Dim TDF new As TableDef
Dim NewDB As Database
If Dir("D:\NewDB.mdb ")" "那么Kill "D:\ NewDB.mdb"
'{取当前目录并删除路径:ifdir ("newdb.mdb ")"那么Kill " newdb . MDB ")}
Set wrk default = dbengine . work spaces(0)
Set DBS new = wrk default。CreateDatabase("d:\NewDB.mdb ",dbLangGeneral,DbEncrypt)
'{取当前目录并删除路径:Set dbnew = wrk default . create database(" newdb . MDB ",dblanggeneral,db encrypt)}
dbnew . new password " "," 123 " '将数据库密码设置为123
setwrk default = nothing
setdbs new = nothing。
末端接头
位律师回复
0条评论