Can anyone tell me how to generate a brand new MS Access Database from within VB? Thanks...
Printable View
Can anyone tell me how to generate a brand new MS Access Database from within VB? Thanks...
Call this routine. (I copy it from the MSDN library, this is not my sample)
Sub CreateDatabaseX()
Dim wrkDefault as Workspace
Dim dbsNew as DATABASE
Dim prpLoop as property
' get default Workspace.
set wrkDefault = DBEngine.Workspaces(0)
' Make sure there isn't already a file with the name of
' the new database.
If Dir("NewDB.mdb") <> "" then Kill "NewDB.mdb"
' Create a new encrypted database with the specified
' collating order.
set dbsNew = wrkDefault.CreateDatabase("NewDB.mdb", _
dbLangGeneral, dbEncrypt)
With dbsNew
Debug.print "Properties of " & .Name
' Enumerate the Properties collection of the new
' Database object.
for Each prpLoop In .Properties
If prpLoop <> "" then Debug.print " " & _
prpLoop.Name & " = " & prpLoop
next prpLoop
End With
dbsNew.Close
End Sub
Create database using ADO
Make sure you have a reference set to the ADOX object library then use the following code.
Dim objCatalog as ADOX.Catalog
Set objCatalog = New ADOX.Catalog
objCatalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\mynewdb.mdb"
Iouri Boutchkine
[email protected]
Dim appAccess as Access.Application
set appAccess = new Access.Application
appAccess.NewCurrentDatabase "C:\WINDOWS\Desktop\MyDB.mdb"
set appAccess = nothing
You will need to add Reference to "Microsoft Access 9.0 Object Library" (ACCESS 2000)
RF