VB中代码创建数据库

时间:2021-01-31 17:15:52
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

'先引用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

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>