PDA

Click to See Complete Forum and Search --> : Create table using Jet.OLEDB.3.51?


hcleo
Mar 31st, 2000, 11:30 AM
Can any one give me the coding for creating the db and the table by using the Jet.OLEDB.3.51 but not the 4.0 one, thanx.

Dr_Evil
Apr 2nd, 2000, 09:24 PM
For the database:

Private Sub NewDatabase_Click()
Dim db As Database

CommonDialog1.ShowSave
If CommonDialog1.FileName <> "" Then
Set db = DBEngine.Workspaces(0).CreateDatabase
(CommonDialog1.FileName, dbLangGeneral)
End If
End Sub


For the table:

Sub CreateTable()
Dim td As TableDef
Dim fields(2) As Field

Set td = db.CreateTableDef(name,attributes,source,connect)

Set fields(0) = td.CreateField(name, type, size)
Set fields(1) = td.CreateField(name, type, size)
td.fields.Append fields(0)
td.fields.Append fields(1)

End Sub


[Edited by Dr_Evil on 04-03-2000 at 10:26 AM]

Clunietp
Apr 4th, 2000, 01:58 PM
That is DAO code, Dr Evil!

Here is ADO code to create a DB:

'use ADO 2.x for DDL and security
Dim strConnectionStringOfNewDB As String
Dim objCat As ADOX.Catalog

'instantiate catalog object
Set objCat = New ADOX.Catalog

'connection string of new db -- includes driver/db type and location
strConnectionStringOfNewDB = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=C:\NewDB.mdb"

'create it
objCat.Create strConnectionStringOfNewDB

'cleanup
Set objCat = Nothing