1. 程式人生 > >VB中程式碼建立資料庫

VB中程式碼建立資料庫

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