Update fields size or type of one table

R

RosuAndreiMihai

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!
 
D

Douglas J. Steele

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
 

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