Hi John,
As Tarren mentioned, you can use T-SQL statements to create your database. However, T-SQL is specific to SQL Server.
You can create Access databases purely at run-time, but not with native ..NET code. For some reason unbeknown to me, it is not available in the ..NET Framework, but it is available with legacy VB 6 DAO code. Also, assuming you are coding a Windows application, you should not need any heightened file system privileges.
Below is a very simple example (be sure to add a reference to the DAO reference library). I didn't test it, but most of it came from a recent project, so it should work with very little modifications. (Also, watch out for line breaks.)
Take care,
Eric
____________________________________
Dim db As DAO.Database
Dim rs As Recordset
Dim dbc As Connection
Dim tbl As DAO.TableDef
Dim idx As DAO.Index
Dim rel As DAO.Relation
Dim fld As DAO.Field
Dim qry As DAO.QueryDef
' Create DB
db = DBEngine.CreateDatabase(App.Path & "\myDatabase.mdb", dbLangGeneral, dbEncrypt)
' Open DB
Set db = DBEngine.OpenDatabase(App.Path & "\myDatabase.mdb")
' Create Customers Table
tbl = db.CreateTableDef("Customers")
' Create an ID field in the Customers table.
fld = tbl.CreateField("CustomerID", dbLong)
' Set schema attributes for the CustomerID column.
fld.Attributes = dbAutoIncrField ' Make CustomerID an AutoNumber field.
tbl.Fields(0).AllowZeroLength = False
tbl.Fields(0).Required = True
' -------------------------------------------------
' INSERT CODE TO ADD MORE COLUMNS
' -------------------------------------------------
' Append the field to the table
tbl.Fields.Append Fld
' Add Companies table to database
db.TableDefs.Append tbl
' Create and append primary key
idx = tbl.CreateIndex("Primary Key")
idx.Primary = True
idx.Fields.Append idx.CreateField("CustomerID")
tbl.Indexes.Append idx
' Create the Customers query
Set qry = db.CreateQueryDef("qryCustomers", _
"SELECT * FROM Customers ORDER BY CustomerID;")
' -------------------------------------------------
' INSERT CODE TO ADD MORE TABLES, ETC.
' -------------------------------------------------
' Create 1:M between [Customers] and [Orders]:
' **********************************************
' (Of course, this assumes Orders table with CustomerID
' column as the foreign key to the Customers table.)
rel = db.CreateRelation()
rel.Name = "CustomersToOrders"
rel.Table = "Customers"
rel.ForeignTable = "Orders"
rel.Attributes = dbRelationDeleteCascade + dbRelationUpdateCascade + dbRelationLeft
' Create linking field:
Fld = rel.CreateField("CustomerID")
' Set ForeignName property of the field to the name of
' the corresponding field in the primary table:
Fld.ForeignName = "CustomerID"
rel.Fields.Append Fld
' Append the relation to the database:
dbs.Relations.Append rel
db.Close