Ken
Here's a sample I cut and pasted from a prior program I worked on
Hope it helps. Note that when appending the items you can specify if the
column data is nullable, a size, a datatype etc etc.
Mike
Private Sub CreateDatabase(ByVal filename As String)
Dim CnnNew As ADODB.Connection
Dim CatNew As ADOX.Catalog
Try
' Open a Connection and create the Catalog (Database)
'
CnnNew = New ADODB.Connection
CatNew = New ADOX.Catalog
CatNew.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & filename & ";" & _
"Jet OLEDB:Engine Type=5")
'Open the connection
CnnNew.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & filename)
'Open the Catalog
CatNew.ActiveConnection = CnnNew
'
'Now build all the Database tables as desired. Add or delete column
'attributes or properties as desired.
'
'Build and add the first Table
'
Dim objDesignTable As New ADOX.Table
With objDesignTable
..Name = "xxxxxxxx"
..ParentCatalog = CatNew
With .Columns
..Append("Units", ADOX.DataTypeEnum.adVarWChar)
..Append("Code", ADOX.DataTypeEnum.adVarWChar)
Append("Change X", adDouble)
..Append("Density", adDouble)
..Append("NA1", adDouble)
..Item("NA1").Attributes = ColumnAttributesEnum.adColNullable
..Append("Occasional Load Factor", adDouble)
..Append("Load Case W1", adBoolean)
..Append("Load Case T1", adBoolean)
..Append("Load X", adDouble)
..Item("Load X").Attributes = ColumnAttributesEnum.adColNullable
..Append("NA2", adDouble)
..Item("NA2").Attributes = ColumnAttributesEnum.adColNullable
..Append("FLAG1", adBoolean)
..Append("FLAG2", adBoolean)
..Append("FLAG3", adBoolean)
End With
'Create and Append a new auto incrementing column to be used
'as the primary key for the table
..Columns.Append("KeyID", adInteger)
..Columns("KeyID").Properties("AutoIncrement").Val ue = True
End With
'Create and Append a new key. Note that we are merely passing
'the "KeyID" column as the source of the primary key. This
'new Key will be Appended to the Keys Collection.
Dim objDesignKey As New ADOX.Key
objDesignKey.Name = "PrimaryKey"
objDesignKey.Type = KeyTypeEnum.adKeyPrimary
objDesignKey.Columns.Append("KeyID")
objDesignTable.Keys.Append(objDesignKey)
'Append the newly created table to the Tables Collection
CatNew.Tables.Append(objDesignTable)
' clean up objects
objDesignKey = Nothing
objDesignTable = Nothing
'. Add or delete column
'attributes or properties as desired.
catch
'error code here
end try
end sub
"Ken Kazinski" <Ke*********@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
Does anyone know of a good example for creating a access database and then
tables within that database.
All the examples I have found so far use a SQL database.
Thanks,
Ken