Click to See Complete Forum and Search --> : ADO question?
Negative0
Jun 28th, 2000, 12:11 AM
Yeah,
You need to reference Microsoft Active X Data Object 2.X library. Try this and then run the code.
Also just a side note, to get data from the database your recordsets should look something like this:
dim RS as New Recordset
RS.Open "SELECT * FROM table",DB,adOpenForwardOnly,adLockReadOnly
Hope this helps
laura
Jun 28th, 2000, 01:09 AM
Negative0,
I added the reference to ADO 2.X and reran the code and it gave me an error something about "Microsoft Run time error, could not find file". Does the code you provide automatically create the file if it's not there?
Thanks, Laura
kb244
Jun 28th, 2000, 01:16 AM
It doesnt create a file there, you will have to make your own mdb in Access. I have no idea how to create a database programatically, but you need a database to start with if you are going to open it. once you got one, then you can add records into a table etc.
Negative0
Jun 28th, 2000, 02:16 AM
Sorry,
I read the post wrong, I thought you just wanted to access the DB, not create it. I am not sure how to create it from code with ADO.
laura
Jun 28th, 2000, 02:52 AM
Thanks everyone!
Does anyone know how to create a "mdb" database using ADO connection thru VB code?
Mongo
Jun 28th, 2000, 04:12 AM
This may help... ;)
Sub ADOCreateDBmitTbl()
Dim cat As New ADOX.Catalog, tbl As New ADOX.Table
' create new mdb
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=[full_filename, i.e., c:\newkid].mdb;"
' if you want to encryt it...
' & "Jet OLEDB:Encrypt Database=True;Jet OLEDB:Engine Type=2;"
' Create a new Table object.
With tbl
.Name = "your_tbl_name"
' Create fields and append them to new Table object.
' You must do this before before appending object
' to Tables collection of Catalog.
.Columns.Append "Field1_name", adVarWChar
.Columns.Append "Field2_name", adVarWChar
.Columns.Append "Field3_name", adLongVarWChar
.Columns("Field3_name").Attributes = adColNullable
' yada, yada...
End With
' Add new table to database.
cat.Tables.Append tbl
Set cat = Nothing
End Sub
laura
Jun 28th, 2000, 04:41 AM
Mongo,
The code you posted is to create new Table. What I need
is to create a new "Database". Is it possible to create
a new empty database with ADO connection using VB code?
Thanks, Laura
Mongo
Jun 28th, 2000, 04:44 AM
This part creates the new mdb:
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=[full_filename, i.e., c:\newkid].mdb;"
laura
Jun 28th, 2000, 08:41 PM
Mongo, thanks for the reply. I tried your code and it works nicely. I also wanted to add password do you know the syntax for that?
Laura
Clunietp
Jun 28th, 2000, 11:25 PM
I believe you add:
;Jet OLEDB:Database Password=MyPassword
to the end of the connection string.....
laura
Jul 31st, 2000, 12:49 PM
How do I create an older Access Database?
What parameters do I use in the cat.create command?
Thanks, Laura
Gary.Lowe
Aug 1st, 2000, 05:04 AM
Laura
Try ';Jet OLEDB:Engine Type=4' in the create bit
i.e.
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=[full_filename, i.e., c:\newkid].mdb;" & _
"Jet OLEDB:Engine Type=4;"
4 = Access 97
5 = Access 2000
Hope this is of use.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.