Create table in Runtime App

Leigh46137

Registered User.
Local time
Today, 18:00
Joined
Dec 29, 2009
Messages
12
I have a database application that I created in Access 2007. It is split to separate the data from the interface. I have made a runtime application to run it on other machines without (full) Access installed.

Now I need to add two more tables to it. I have added very simple tables before, but this time I need to specify certain attributes for the fields and I don't know how to do that. I need one field to be a primary key field using AutoNumber, another to be a date field defaulting to the current date using the short date format, and other text and numeric fields that are required and cannot be blank.

Here is the code I have so far, that just creates the basic table and fields:

Dim db As Database
Dim td As TableDef
Dim fd As Field
Dim stFile As String

stFile = ChooseFile()
Set db = OpenDatabase(stFile)

Set td = db.CreateTableDef("Quotes")
td.Fields.Append td.CreateField("QuoteID", dbLong)
td.Fields.Append td.CreateField("Customer", dbText, 50)
td.Fields.Append td.CreateField("QuoteDate", dbDate)
td.Fields.Append td.CreateField("PricingLevel", dbLong)
db.TableDefs.Append td


Can anyone tell me how to set the field attributes that need?

Thanks!
 
Google "Access ALTER TABLE" and you find sample code.

Access Databases, 3rd Edition by O'Rielly, about $40 new, is an excellent resource for, among other things, creating tables with DAO code (your method) and with SQL code.
 

Users who are viewing this thread

Back
Top Bottom