Update fields size or type of one table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there!
Can anyone help me?
I have a database and i need to modifie the size and type property of fields
in tables from code.
I used DAO for reading tables, and I had a ideea like this:
dim db as database
set db = Currentdb
....
db.tabledefs("Table").Fields("Field1").Type = NewValue
db.tabledefs("Table").Fields("Field1").Size = NewValue
....
But it doesn't work!
 
Both the Type and Size properties are read-only once you've appended the
field to a table.

Using DAO, you can create a new field with the correct properties, run an
Update query to populate the new field with the old values, delete the old
field and rename the new field. (Don't forget to compact the database after
you do this)

Your other option is to use DDL. To change the characteristics of a field,
the DDL would be something like:

strDDL = "ALTER TABLE File " & _
"ALTER COLUMN YearValue Text(50)"

You'd run this as:

db.Execute strDDL, dbFailOnError
 
Back
Top