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?
Rog DConnect With a Mentor Manager Inforamtion SystemsCommented:
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

Rog DConnect With a Mentor Manager Inforamtion SystemsCommented:
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

MarcGraffAuthor Commented:
Thanks so much!

   - Marc
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Rog DManager Inforamtion SystemsCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.