Change Text Field Length

J

Jay Vinton

How can I change the length of a text field programatically?

Hi Lou,

The Size property is read-only for an existing field so you need to create a new field with the new size, copy the data from the old field to the new field, delete the old field and rename the new field to the old name. You may lose data if the new size is smaller than the old size.

Something like this sets the size to 189:

Dim db As Database
Dim td As TableDef

Set db = CurrentDb
Set td = db.TableDefs("TableName")

With td

.Fields.Append .CreateField("tmp", dbText, 189)
db.Execute "update TableName set tmp = OldName;", dbFailOnError
.Fields.Delete "OldName"
.Fields("tmp").Name = "OldName"

End With

Jay
 

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