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!

Change Field Decimal Place from Auto using VB

Status
Not open for further replies.

DanScott

Programmer
Sep 13, 2002
14
US
I have a piece of code I am using to create a table:

dim db as database
dim tdf as TableDef
dim strnewtable as string


db = currentdb()
Set db = OpenDatabase("h:\customer\master.mdb")
Set tdf = db.CreateTableDef(strNewTable)

With tdf
.Fields.Append .CreateField("NAME2", dbText, 10)
.Fields.Append .CreateField("BALANCE", dbDOUBLE)
db.TableDefs.Append tdf
End With
tdf.Fields("NAME2").AllowZeroLength = True


This is not the complete code and does work in its entirity, but I thought this would give a good idea of what I am doing. My problem is, when I then proceed to fill the table with data, the default is auto on decimal places for the balance field I created, so if there is a zero after the decimal place it removes it. ie.... 123.30 = 123.3 or 123.00 = 123

I need to change the decimal place on the table to two before bring in the data, can anyone help?

 
Try something like this:

Sub test()

Dim dbs As DAO.Database
Dim tbl As DAO.TableDef
Dim fld As DAO.Field

Set dbs = CurrentDb()
Set tbl = dbs.TableDefs("YourTable")
Set fld = tbl.Fields("YourField")

fld.Properties("DecimalPlaces") = 2
fld.Properties("Format") = "Fixed"

End Sub

Of course, you can adjust the decimal places accordingly.




-Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top