Visual Basic/VB >> Set Decimal Places on a field

by DIOS » Tue, 07 Oct 2003 12:05:09 GMT

I have code whcih lets me update properties of fields
of an Access97 database via VB/DAO.
I can update "Format" but "Decimal Places" just will
not work. Has anyone done this successfully?

Im using the code snippet from this site:
http://visualbasic.about.com/library/weekly/aa101602a.htm

AGP

--

**********************************************************************
Unpak my email address before sending me personal email
**********************************************************************




Visual Basic/VB >> Set Decimal Places on a field

by Douglas J. Steele » Wed, 08 Oct 2003 06:57:41 GMT


What's the data type of the field?









Visual Basic/VB >> Set Decimal Places on a field

by DIOS » Wed, 08 Oct 2003 08:08:56 GMT

Currency....the Format sets right but not the Decimal Places

AGP

--

**********************************************************************
Unpak my email address before sending me personal email
**********************************************************************









Set Decimal Places on a field

by DIOS » Wed, 08 Oct 2003 10:01:16 GMT

OK I had the Property type wrong..I was using dbInteger instead of dbByte.
Here is what I used:

Set TempTDef = NewDB.TableDefs("tblFiles")
Set TempField = TempTDef.Fields("FileSize")

TempField.Properties.Append TempField.CreateProperty("Format", dbText,
"#;#;0;""Null""")
TempField.Properties.Append TempField.CreateProperty("DecimalPlaces",
dbByte, 0)
TempField.Properties.Refresh
TempTDef.Fields.Refresh

and that works! :)

AGP



--

**********************************************************************
Unpak my email address before sending me personal email
**********************************************************************











Similar Threads

1. Set Decimal Places on a field

2. Zero's after decimal place in Text fields

I have a function that performs a few calculations with numbers and when I
return the value to the text field in the report I always get decimal and
two trailing zero's.
How can I make the decimal and trailing zeros go away.
I the properties of the text field I have Decimal Places set to 0.

Example of Function

formula = CStr( myNumber )

Gary



------------------------------------------
Gary Paquette



3. Can I format the field to 2 decimal places in my sql

4. Define Decimal Places in new field

I need to add a couple of new fields to a table in an access db. The 
fields are of type dbSingle with 2 decimal places.

I cant find where or how to define the decimal places in code.  If after 
creating a new field I try to set the "DecimalPlaces" property I get an 
error.  To avoid this error I append a new property called 
"DecimalPlaces" of type Integer and value=2.  Then I look at the table in 
design view, the Decimal Places property shows as Auto.  If I change this 
value in the table in design view and then read the value of the 
DecimalPlaces property in code, the value returned reflects the change 
that I made in design view.

Here is the code that Im using


Function Update_AddPerCentageFields()
    
    Dim dbs As Database
    Dim tdf As DAO.TableDef
    
    Set dbs = CurrentDb
    Set tdf = dbs.TableDefs("Table1")
    
    With tdf
        .Fields.Append .CreateField("NewField", dbSingle)
        
'if I try to refer to "DecimalPlaces" now I get an error so 
'I append the property

        .Fields("NewField").Properties.Append _
    	    	    	.CreateProperty ("DecimalPlaces", dbInteger, 2)

        
    End With
End Function

Any ideas on this?

Many thanks 

terry holland

5. How do I set Decimal Places

6. Setting Decimal Places in a Word Table

I have a Word 2007 table with two columns that contain numbers. My client 
wants these numbers to reflect one decimal place. This document is fielded to 
serveral locations and I do not wish to involve Excel in "importing a table". 
There has to be a simple way to accomplish this. Maybe a macro?

7. truncating a decimal to 2 decimal places?? - VB.Net

8. setting the decimal variable to include 2 numbers after decimal po

Try using this overload of the Decimal.ToString(String) class, I think if you 
pass a "C" to this overload you'll get currency format beyond that you'll 
have to consult the NumberFormatInfo class.

"Scott" wrote:

> How do I declare the decimal variable to include money...
> 
> If want to use money and instead of vb.net displaying 32.2 I want it to 
> display 32.20!!!
> 
> How do I do this. cant find it anywhere???
> 
> Scott 
> 
> 
>