ADO equivalent for creating access database

I have this DAO code that I used to create and load an access database into my application when the application opens.  I was wondering if someone could tell me how to do the same thing using ADO.  Thanks.

Set ws = DBEngine.Workspaces(0)
Set db = ws.CreateDatabase(Userfile, dbLangGeneral, dbVersion30)
Set db = ws.OpenDatabase(Userfile)
Set td = db.CreateTableDef("ValExp")
With td
    .Fields.Append .CreateField("Stock Name", dbText, 40)      '0
    .Fields.Append .CreateField("Stock Symbol", dbText, 6)      '1
    .Fields.Append .CreateField("Stock Price", dbSingle)        '2
    .Fields.Append .CreateField("Est Date", dbDate)             '3
    .Fields.Append .CreateField("Est Year", dbText, 6)          '4
    .Fields.Append .CreateField("Price High(0)", dbSingle)      '5
    .Fields.Append .CreateField("Price High(1)", dbSingle)      '6
    .Fields.Append .CreateField("Price High(2)", dbSingle)      '7
    .Fields.Append .CreateField("Price High(3)", dbSingle)      '8
    .Fields.Append .CreateField("Price High(4)", dbSingle)      '9
    .Fields.Append .CreateField("Price High(5)", dbSingle)      '10
    .....
End With

db.TableDefs.Append td

Set rs = db.OpenRecordset("ValExp", dbOpenDynaset)
rs.AddNew
rs.Update
rs.MoveFirst

End Sub
jfyfeAsked:
Who is Participating?
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.

TimCotteeHead of Software ServicesCommented:
Try this, it might get you started, you will probably need to sort out some of the bits, but it does sort of work. The main problem I had doing this was that when you try to open this directly in access it doesn't like the database format ( I don't know why!)

Let me know how you get on though.

    Dim catAccess As New ADOX.Catalog
    Dim tblValExp As New ADOX.Table
    Dim cnnAccess As New ADODB.Connection
    Dim rstValExp As New ADODB.Recordset
    catAccess.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\test1.mdb"
    catAccess.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\test1.mdb"
    With tblValExp
        .Name = "tblValExp1"
        .Columns.Append "Stock Name", adVarWChar, 40
        .Columns.Append "Stock Symbol", adVarWChar, 6     '1
        .Columns.Append "Stock Price", adSingle       '2
        .Columns.Append "Est Date", adVarWChar, 10           '3
        .Columns.Append "Est Year", adVarWChar, 6         '4
        .Columns.Append "Price High(0)", adSingle     '5
        .Columns.Append "Price High(1)", adSingle     '6
        .Columns.Append "Price High(2)", adSingle     '7
        .Columns.Append "Price High(3)", adSingle     '8
        .Columns.Append "Price High(4)", adSingle     '9
        .Columns.Append "Price High(5)", adSingle     '10
    End With
    catAccess.Tables.Append tblValExp
    Set tblValExp = Nothing
    Set catAccess = Nothing
    cnnAccess.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\test1.mdb;Persist Security Info=False"
    rstValExp.Open "SELECT * FROM tblValExp1", cnnAccess, adOpenKeyset, adLockOptimistic
    rstValExp.AddNew
    rstValExp.Fields(0).Value = "Name"
    rstValExp.Fields(1).Value = "Symbol"
    rstValExp.Fields(2).Value = 1.5
    rstValExp.Fields(3).Value = Format(Now(), "dd/mm/yyyy")
    rstValExp.Fields(4).Value = "2000"
    rstValExp.Fields(5).Value = 1.5
    rstValExp.Fields(6).Value = 1.5
    rstValExp.Fields(7).Value = 1.5
    rstValExp.Fields(8).Value = 1.5
    rstValExp.Fields(9).Value = 1.5
    rstValExp.Fields(10).Value = 1.5
    rstValExp.Update
    rstValExp.MoveFirst
    Set rstValExp = Nothing
    Set cnnAccess = Nothing
0

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
jfyfeAuthor Commented:
Thanks for answering so quickly.  Didn't know I could use ADOX (or even what is was) until now.  Your code along with http://msdn.microsoft.com/library/officedev/off2000/achowDAOToADOX.htm did the trick.
0
jfyfeAuthor Commented:
Tim, don't know if you figured it out, but I think by adding "Jet OLEDB:Engine Type=4" to the Create statement, it will allow you to open the database in Access.

cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                       "Data Source=" & Userfile & ";" & _
                       "Jet OLEDB:Engine Type=4;"

I also have a pending question about how to allow null records.  Can you help?
0
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.