以ms-access创建数据库,然后删除特定数据库。使用任何vb查询或vb代码

时间:2008-11-26 07:07:27

标签: ms-access access-vba

我想使用代码或ms-access的任何选项在ms-access中创建许多数据库,但我也想要删除数据库。             请帮帮我

2 个答案:

答案 0 :(得分:3)

您可以拥有一个名为“db1.mdb”的空数据库,然后将此代码添加到另一个 Access数据库中的模块中:

  Set fso = CreateObject("scripting.filesystemobject")
  fso.CopyFile "c:\db.mdb", "c:\db_copy1.mdb", True
  fso.CopyFile "c:\db.mdb", "c:\db_copy2.mdb", True
  fso.CopyFile "c:\db.mdb", "c:\db_copy3.mdb", True
  fso.DeleteFile "c:\db.mdb"

答案 1 :(得分:1)

从Access界面创建 Access 数据库:

createDatabase "myNewMDB.mdb", dbLangGeneral

要删除数据库:

kill "myNewMDB.mdb"

没有初始mdb文件或额外的dll

用于多个数据库

public Function createDeleteDatabase(howManyDatabases as integer) as boolean

''output is by default False
createDeleteDatabase = False

on error goto createDeleteDatabase_Error

Dim i as integer
For i = 1 to howManyDatabases
    createDatabase "myMDBNumber_" & str(i,0) & ".mdb", dbLangGeneral
Next i
For i = 1 to howManyDatabases
    kill "myMDBNumber_" & str(i,0) & ".mdb"
Next i

''if no errors in the fonction, set the output to True
createDeleteDatabase = True

Exit function
createDeleteDatabase_Error:
'' your error treatment
End function