CSDN博客

img Athoncj

VB代码创建数据库

发表于2004/4/26 12:46:00  1549人阅读

'先引用Mcrsoft DAO 3.6(或2.5或3.51) Object Library和Mcrsoft Access 9.0 Object Library,在Form上加个Command1,粘贴以下代码:

Private Sub Command1_Click()
   Dim wrkDefault As Workspace
   Dim dbsNew As Database
   Dim tdfNew As TableDef
   Dim NewDB As Database

   If Dir("D:/NewDB.mdb") <> "" Then Kill "D:/NewDB.mdb"
      '{取当前目录的话去掉路径: If Dir("NewDB.mdb") <> "" Then Kill "NewDB.mdb")}
   Set wrkDefault = DBEngine.Workspaces(0)
   Set dbsNew = wrkDefault.CreateDatabase("d:/NewDB.mdb", dbLangGeneral, dbEncrypt)
      '{取当前目录的话去掉路径: Set dbsNew = wrkDefault.CreateDatabase("NewDB.mdb", dbLangGeneral, dbEncrypt)}
      
   dbsNew.NewPassword "", "123" '设置数据库密码为123
  
  
   Set wrkDefault = Nothing
   Set dbsNew = Nothing

End Sub

0 0

相关博文

我的热门文章

img
取 消
img