Solved

How to Creat a blank access 2000 database in VB

Posted on 2003-11-05
6
179 Views
Last Modified: 2010-05-03
How would one generate a blank access 2000 database called "Backup.mdb" in vb code?

   - Marc
0
Comment
Question by:MarcGraff
  • 3
  • 3
6 Comments
 
LVL 8

Assisted Solution

by:Rog
Rog earned 250 total points
ID: 9689176
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

 dbsNew.Close

End Sub


0
 
LVL 8

Accepted Solution

by:
Rog earned 250 total points
ID: 9689211
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"
cn.Open
 
Set rs = New ADODB.Recordset
rs.Open "SELECT column1,column2 FROM MyTable", cn, adOpenDynamic,
adLockOptimistic
rs.AddNew
rs!column1 = 1
rs!column2 = "First Value"
rs.Update

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

0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9689337
Thanks so much!

   - Marc
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:Rog
ID: 9689347
Are you then going to accept this as an answer?


Thanks,

Rog
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9689373
I will, just trying to get it to work right.

   - Marc
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9689380
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now