How to Creat a blank access 2000 database in VB

How would one generate a blank access 2000 database called "Backup.mdb" in vb code?

   - Marc
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rog DSQL Developer / Web Development / Business AnalysisCommented:
Make sure your project has references to the Microsoft DAO 3.51 Object Library.

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


End Sub

Rog DSQL Developer / Web Development / Business AnalysisCommented:
Actually you might want to use Dao 3.6 for an  access 2000 database.  This one uses ADOX object instead of the DAO.  One of these should work.

Also here is another example for you that shows better how to create tables too....

Actually, to create a new database, we need to use the ADOX object. We can
use the ADOX object to defining and retrieving a database's shema such as
database, tables. Here are some sample codes for your reference:

Private Sub Form_Load()

'if the database file already exists, kill it
If Dir("c:\newmdb.mdb") <> "" Then
    Kill "c:\newmdb.mdb"
End If

Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
Set PrimaryKey = New ADOX.Key

cat.Create "Provider= Microsoft.Jet.OLEDB.4.0" & _
              ";Data Source=c:\newmdb.mdb" & _
              ";Jet OLEDB:Engine Type=4"

  tbl.Name = "MyTable"
  tbl.Columns.Append "Column1", adInteger
  tbl.Columns.Append "Column2", adVarWChar, 50
  cat.Tables.Append tbl
  PrimaryKey.Name = "Column1"
  PrimaryKey.Type = adKeyPrimary
  PrimaryKey.Columns.Append "Column1"
  cat.Tables("MyTable").Keys.Append PrimaryKey

Set cat = Nothing
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider= Microsoft.Jet.OLEDB.4.0" & _
              ";Data Source=c:\newmdb.mdb"
Set rs = New ADODB.Recordset
rs.Open "SELECT column1,column2 FROM MyTable", cn, adOpenDynamic,
rs!column1 = 1
rs!column2 = "First Value"

Do While rs.EOF = False
    Debug.Print "Key : " & rs!column1 & "  Value :  " & rs!column2
End Sub


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarcGraffAuthor Commented:
Thanks so much!

   - Marc
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Rog DSQL Developer / Web Development / Business AnalysisCommented:
Are you then going to accept this as an answer?


MarcGraffAuthor Commented:
I will, just trying to get it to work right.

   - Marc
MarcGraffAuthor Commented:
It is saying I need to convert the database to access 2000 when I open it and I am working on what I did wrong.

   - Marc
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.