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.Connectio n
Dim CatNew As ADOX.Catalog
Try
' Open a Connection and create the Catalog (Database)
'
CnnNew = New ADODB.Connectio n
CatNew = New ADOX.Catalog
CatNew.Create(" Provider=Micros oft.Jet.OLEDB.4 .0;" & _
"Data Source=" & filename & ";" & _
"Jet OLEDB:Engine Type=5")
'Open the connection
CnnNew.Open("Pr ovider=Microsof t.Jet.OLEDB.4.0 ;" & "Data Source=" & filename)
'Open the Catalog
CatNew.ActiveCo nnection = 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.DataTypeEn um.adVarWChar)
..Append("Code" , ADOX.DataTypeEn um.adVarWChar)
Append("Change X", adDouble)
..Append("Densi ty", adDouble)
..Append("NA1", adDouble)
..Item("NA1").A ttributes = ColumnAttribute sEnum.adColNull able
..Append("Occas ional Load Factor", adDouble)
..Append("Load Case W1", adBoolean)
..Append("Load Case T1", adBoolean)
..Append("Load X", adDouble)
..Item("Load X").Attribut es = ColumnAttribute sEnum.adColNull able
..Append("NA2", adDouble)
..Item("NA2").A ttributes = ColumnAttribute sEnum.adColNull able
..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.Appen d("KeyID", adInteger)
..Columns("KeyI D").Properties( "AutoIncrement" ).Value = 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.Na me = "PrimaryKey "
objDesignKey.Ty pe = KeyTypeEnum.adK eyPrimary
objDesignKey.Co lumns.Append("K eyID")
objDesignTable. Keys.Append(obj DesignKey)
'Append the newly created table to the Tables Collection
CatNew.Tables.A ppend(objDesign Table)
' 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*********@di scussions.micro soft.com> wrote in message
news:42******** *************** ***********@mic rosoft.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