Change field datatype code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I was wondering if it is possible to change the datatype of an existing
field in code ? I was trying something like:
db.TableDefs("Table1").Fields("Field1").Properties ("type") = dbText

but this does not seem to work.

Marco
 
Hi,

I was wondering if it is possible to change the datatype of an existing
field in code ? I was trying something like:
db.TableDefs("Table1").Fields("Field1").Properties ("type") = dbText

but this does not seem to work.
it doesn't work
you can make add new field, copy the data and delete the old field

or

db.execute "ALTER TABLE Table1 ALTER COLUMN Field1 TEXT(xx)"
where xx is the length you want, without you get 255
 
Hello,

If I want to do the same thing but change it from text to numeric, how do I
define what type of numeric (i.e. single, double, integer, long integer, etc.)

Jessica
 
The values for the Type property are dbBoolean, dbByte, dbCurrency, dbDate,
dbDecimal, dbDouble,
dbInteger, dbLong, dbMemo and dbSingle
 
I orginally had the following in a module:

CurrentDb.Execute "ALTER TABLE JessicaTest ALTER COLUMN tobit02 NUMERIC"

which turned it to a numeric, double field.

I tried:
CurrentDb.Execute "ALTER TABLE JessicaTest ALTER COLUMN tobit01 NUMERIC
(dbSingle)"

and got an error message of: "Syntax error in ALTER TABLE statement."

Then I tried:
CurrentDb.Execute "ALTER TABLE JessicaTest ALTER COLUMN tobit01 NUMERIC
(dbSingle)"
and got an error message of "There is no field named 'dbsingle' in the table
'JessicaTest'.

Any thoughts on how to get around these errors?

Jessica
 
Sorry, the values I gave were intended for the first solution, using DAO
(sorry I wasn't more explicit)

I'm afraid I don't have a comprehensive list of types for the ALTER COLUMN
syntax. Try using SINGLE rather than NUMERIC.
 
Jessica, did you find a solution to your problem? I'm trying to set a field
to Decimal.
 
Back
Top