ansi
August 12th, 2001, 02:11 PM
Can anyone tell me how to generate a brand new MS Access Database from within VB? Thanks...
|
Click to See Complete Forum and Search --> : Creating a new Access DB ansi August 12th, 2001, 02:11 PM Can anyone tell me how to generate a brand new MS Access Database from within VB? Thanks... thinman August 13th, 2001, 05:28 AM 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 Iouri August 13th, 2001, 06:50 AM 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 iouri@hotsheet.com Raptors Fan August 13th, 2001, 10:28 AM 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 codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |