Create databases in ms access and then drop a specific database. using any vb request or vb code

I want to create multiple databases in ms-access using code or any ms-access option, but also want to drop the databases. Please help me

0


source to share


2 answers


You can have an empty database named "db1.mdb" and then add this code inside a module to another Access database:



  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"

      

+3


source


To create a database Access from the access interface:

createDatabase "myNewMDB.mdb", dbLangGeneral

      

To drop a database:

kill "myNewMDB.mdb"

      



It works without an initial mdb file or additional dlls

for multiple databases

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

      

+1


source







All Articles