Specifying (table) field parameters from VBA code

David Thorpe

New member
Local time
Today, 16:00
Joined
Apr 11, 2003
Messages
6
I am new to code writing and am beginning, with the aid of a couple of doorstop sized text-books books, by generating tables. So far, I have managed to create tables with various field types, such as text, date, number, currency etc. What defeats me is how to code other properties such as format, validation rule, required, indexed etc.

For example, to add a 16 character NAME column I am using .Columns.Append "NAME", adWChar, 16 - but how should I go about specifying other parameters?

I would appreciate help from anybody who can give me some guidance.

Thank you in anticipation

David T.
 
After appending your table defs (or however you've created your tables) call something along the lines of

Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim idx As DAO.Index

' Open the database
Set db = CurrentDb
Set tbl = db.TableDefs(strTblName)

' Create Index object append Field object to the Index object.
Set idx = tbl.CreateIndex("AccountIndex")

idx.IgnoreNulls = True
idx.Fields.Append idx.CreateField("Account")
idx.Fields.Append idx.CreateField("Code")
idx.Required = True

' Append the Index object to the
' Indexes collection of the TableDef.
tbl.Indexes.Append idx
 
Mark,

Thank you for your very quick response - but I am not sure your solution will work for me. I said I was new to this coding business and now realise I should have mentioned that I am working in ADO mode (as my doorstop text-books recommend this) and not DAO (last week I did not know the difference, so I guess that is progress).

Do you know the ADO equivalent of your DAO method?

Regards,

David T.
 

Users who are viewing this thread

Back
Top Bottom