Full Version: Adding Columns to a Table using code
UtterAccess Discussion Forums > Microsoft® Access > Access Tables + Relationships
mwacardsfan
Anyone know how to use code to add columns to an existing table?
freakazeud
Hi,
check out the alter command:

Currentdb.Execute "Alter Table TableName Add Column FieldName Text"

You can find more examples searching on UA.
HTH
Good luck
mwacardsfan
great. Thanks.

One other quick question. how do you define the new column's format to be anything other than text?

Such as integer, double, percent?

Thanks again.
freakazeud
As mentioned search UA.
Instead of text define it as whatever you want. The syntax is:

CurrentDB.Execute "ALTER TABLE tableName ADD COLUMN columnName DataType"

datatype:

DATETIME
Text
BoolField YESNO
Integer
Single
Double
...

HTH
Good luck
mwacardsfan
thanks1
freakazeud
You're welcome.
Glad I could assist!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.