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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Code to define database Fields

Status
Not open for further replies.

33216CLC

Programmer
Aug 17, 2000
173
BS
Hi,

I use code to add fields or tables to my Access database. This process works fine, but I would like to be able to define the number of decimal places for a field using code. Presently, using the code below, the decimal places will be set to auto? Is there an argument that I can add to this line of code to get what I need?


tables.Fields.Append .CreateField("OT1Rate", dbCurrency)

Thanks
 
Currency datatype is automatically set to 4 decimal places.

Chip H.
 
Hi Chip,

Is there a way for me to set it to 2dp's using code?

Thanks
 
No, by definition currency is 4 decimal places, if you want 2 decimal places use a numeric and specify the number you want.

From the sql books online:

decimal and numeric
Numeric data types with fixed precision and scale.

decimal[(p[, s])] and numeric[(p[, s])]

Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The SQL-92 synonyms for decimal are dec and dec(p, s).

p (precision)

Specifies the maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision. The maximum precision is 38.

s (scale)

Specifies the maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p. The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision.

Precision Storage bytes
1 - 9 5
10-19 9
20-28 13
29-38 17

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top