Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change field type from code

Status
Not open for further replies.

elibb

Programmer
Oct 22, 2001
335
MX
hi, i have a vb6.0 application, and i want to modify a field on my Access database, by changing its data type from Number to Text, but i need to do it by code, so my user doesnt have to get in the database in design and change it.
does anybody how to do it?

thank you very much

Eli
 
I don't think that you can directly. Here's what Access has to say about the "Field.Type" property.

"... The setting or return value is a constant that indicates an operational or data type. For a Field or Property object, this property is read/write until the object is appended to a collection or to another object, after which it's read-only. ..."

You would probably need to go the much more labor-intensive route of creating a new field; adding it to the table; copying and converting values to the new field; delete the old field; rename the new field and reposition it in the table to the location where the old field was.
 
thank You very much, but actually i found a way:

Code:
"Alter table myTable Alter column myField varchar(50)"

that will change myField from Integer to text..

i think it works fine

ELi
 
Interesting. I get a syntax error when I attempt that. According to my documentation the allowed options are "COLUMN ADD" and "COLUMN DROP" ... nothing about changing an existing column. Must be something new in your version of Access.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top