|
-
Jun 28th, 2000, 12:11 AM
#1
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:
Code:
dim RS as New Recordset
RS.Open "SELECT * FROM table",DB,adOpenForwardOnly,adLockReadOnly
Hope this helps
-
Jun 28th, 2000, 01:09 AM
#2
Member
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
-
Jun 28th, 2000, 01:16 AM
#3
Addicted Member
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.
-
Jun 28th, 2000, 02:16 AM
#4
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.
-
Jun 28th, 2000, 02:52 AM
#5
Member
Thanks everyone!
Does anyone know how to create a "mdb" database using ADO connection thru VB code?
-
Jun 28th, 2000, 04:12 AM
#6
Hyperactive Member
This may help... 
Code:
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
-
Jun 28th, 2000, 04:41 AM
#7
Member
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
-
Jun 28th, 2000, 04:44 AM
#8
Hyperactive Member
This part creates the new mdb:
Code:
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=[full_filename, i.e., c:\newkid].mdb;"
-
Jun 28th, 2000, 08:41 PM
#9
Member
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
-
Jun 28th, 2000, 11:25 PM
#10
Guru
I believe you add:
;Jet OLEDB:Database Password=MyPassword
to the end of the connection string.....
-
Jul 31st, 2000, 12:49 PM
#11
Member
How do I create an older Access Database?
What parameters do I use in the cat.create command?
Thanks, Laura
-
Aug 1st, 2000, 05:04 AM
#12
Fanatic Member
Laura
Try ';Jet OLEDB:Engine Type=4' in the create bit
i.e.
Code:
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.
Gary Lowe 
VB6 (Enterprise) SP5
ADO 2.6
SQL Server 7 SP3
OK I know my spelling and grammer is crap so don't quote me on it!
To err is human to take the P! is only natural !!
Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|