First, I recommend that you not use the Decimal
data type in Access 2003 because there are bugs with it around sorting (wrong order) and aggregating (sums truncating the fractional portion). In Access 2007 the aggregate problem is solved but not the sorting (though you can supposedly fix this in Access 2007 by putting an index on the column).
As for your script, there are two obvious problems:
You must use ADD COLUMN ColumnName
not ADD ColumnName
The correct data type is DECIMAL
, because NUMBER
creates a double-precision float instead, and doesn't allow parentheses after it specifying any kind of size. (Maybe NUMERIC
would work as a synonym of DECIMAL
but I don't know.)
So this should work for you:
ALTER TABLE EMP_2 ADD COLUMN EMP_PCT DECIMAL(4,2);
According to HansUp and other sources, this cannot be submitted through DAO (as in CurrentDb.Execute
) but must be done via ADO (CurrentProject.Connection.Execute
).
Apparently, there is a way to get this SQL working but it requires a database settings change:
The decimal data type isn't supported in the default Jet 4.0 mdb file. You have to use the SQL Server compatibility syntax (ANSI 92) setting to use the decimal data type in the SQL Window.
Click on the menu, Tools > Options. Click on the Tables/Query tab. Mark the check box for "This database" in the SQL Server compatibility syntax (ANSI 92) section. This mode will affect the entire db, including queries with wildcards, so you may want to try this on a copy of your db.
If you still cannot get things working, you might consider this method (thanks to Philippe Grondier):
Dim TD As DAO.TableDef
Dim F As DAO.Field
Set TD = CurrentDb.TableDefs("TableName")
Set F = TD.CreateField("FieldName", dbDecimal, 4)
F.DecimalPlaces = 2
F.DefaultValue = 0
TD.Fields.Append F
For reference, here are some related Microsoft.com help pages: