A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Change Text Field Length



 
 
Thread Tools Display Modes
  #1  
Old July 27th, 2004, 09:51 PM
Lou Civitella
external usenet poster
 
Posts: n/a
Default Change Text Field Length

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

TIA,
Lou


  #2  
Old July 27th, 2004, 11:46 PM
Jay Vinton
external usenet poster
 
Posts: n/a
Default Change Text Field Length

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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASK Field Behavior Greg Mailmerge 9 July 2nd, 2004 02:44 PM
NUMBERING the pages Bob New Users 7 June 14th, 2004 12:20 AM
How to update or change a text field Le Tran New Users 2 May 19th, 2004 07:51 PM
Converting Field Names to Text Dawn General Discussion 1 May 16th, 2004 07:57 AM
Text Box in table woes. :( JOE Tables 10 May 5th, 2004 01:21 AM


All times are GMT +1. The time now is 02:20 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.