Set Field size in VBA

  • Thread starter Thread starter Vincent
  • Start date Start date
V

Vincent

I'm want to set the fieldsize of some fields in some
table...
I use a For loop to run through all fields but when a want
to set the size property
(like this: rst.Fields(i).size = 12) I get a runtime error
3219 "Invalid operation"
How comes... apparently in the help it's not said that the
property is Read-only.
Thanks for your help.
 
I don't believe you can resize a field like that.

If you are using Access 2000 or later, with a reference to the ADO library,
you can change the field size like this:
strSQL = "ALTER TABLE MyTable ALTER COLUMN MyField TEXT(12);"
CurrentProject.Connection.Execute strSQL

If you must work with DAO, the typical workaround is to create another field
of the desired size, exeucte an Update query to copy the data from the old
field, and then delete the old field.
 
Don't know what version of Help you're using, but in Access 97 (the last
version with reasonable help), it explicitly states that it's read-only for
objects appended to TableDef objects.
 
Back
Top