Create tables using Queries

E

Enver Buzoku

How can I set default values for table fields that I create using queries!
I have tried similar syntax to SQL but it does not work.


Can someone translate this into access friendly code, please!
Thanks in advance!

CREATE TABLE EDIT_LOG (
RECORD_ID INT NOT NULL ,
RECORD_TYPE INT NOT NULL DEFAULT 0,
EVENT_TIME DATETIME NOT NULL DEFAULT GETDATE(),
OPERATOR VARCHAR (50) NOT NULL ,
AMOUNT MONEY NOT NULL
)

Cheers!
 
P

Peter

The following should help in your translation and indicate the way to set
defaults-

Dim tdfNew As TableDef
' Create a new TableDef object.
Set tdfNew = CurrentDb(0).CreateTableDef("EDIT_LOG")

With tdfNew
.Fields.Append .CreateField("RECORD_ID", dbInteger)
.Fields.Append .CreateField("RECORD_TYPE", dbInteger)
.Fields.Append .CreateField("EVENT_TIME", dbDate)
.Fields.Append .CreateField("OPERATOR", dbText, 50)
.Fields.Append .CreateField("AMOUNT", dbCurrency)
.Fields("RECORD_TYPE").DefaultValue = 0
.Fields("EVENT_TIME").DefaultValue = Now()
For i = 0 To 5
.Fields(1).AllowZeroLength = False
Next i
End With


Peter
 
E

Enver Buzoku

I need to execute a query over an ADO connection.

Well, that is good but not what I need!
Thanks for your effort Peter!

Cheers Enver!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top