Set Field size in VBA

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.
 
A

Allen Browne

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.
 
V

Vincent

Thank you very much Allen!!! Your first solution seems to
me the most elegant... Thanks again... dum from me that I
didn't think about it before... but that why newsgroup
exist...
Vincent
 

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