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

How to set "Format" and "Decimal Places" properties? 1

Status
Not open for further replies.

WaltW

MIS
Jun 14, 2000
130
US
I'm trying to use VBA in MS Access 97 to create a new table. I've had no problem creating the table and the fields. But one of the numeric fields needs to have its "Field Size" property set to "Double", its "Format" property set to "Fixed", and its "Decimal Places" property set to "2". I've tried a few things, but so far haven't been able to do this from within VBA. Can somebody give me some ideas how to do this in VBA? Any help at all would be greatly appreciated. Thanks!

WaltW
 
You can set it to double when you create the field just by specifying the type as dbDouble. I found one way to change the decimal places of a double field. The problem is that it worked in one table but not another. It has to recognize that the property's there. I didn't see a Format property, but you could try the same with it.

CurrentDb.TableDefs(&quot;<tblname>&quot;).Fields(&quot;<fldname>&quot;).Properties(&quot;DecimalPlaces&quot;) = 2
 
Thanks for the message, but in my table this didn't work - I get a &quot;Property not found&quot; error. In the Help for MS Access 97, it makes a distinction between setting DAO properties and setting MS Access properties for DAO objects. I found the following in Help, under the heading &quot;Setting Microsoft Access Properties for DAO Objects&quot;: &quot;When you set a property that's defined by Microsoft Access, but applies to a DAO object, the Jet database engine doesn't automatically recognize the property as a valid property. The first time you set the property, you must create the property and append it to the Properties collection of the object to which it applies. Once the property is in the Properties collection, it can be set in the same manner as any DAO property.&quot;

The DecimalPlaces property is listed as one of the MS Access properties that falls in the above category. I've tried &quot;creating&quot; the DecimalPlaces property, so I can set it, but I haven't been able to get that to work either. Any other ideas? Again, thanks for any help offered!

WaltW
 
I found the problem - you do have to create the DecimalPlaces property, but I was also creating the table def at the same time, and was trying to create and append the property BEFORE I had actually appended the table def (silly me!). Once I created fields and appended the table def FIRST, I could go in and create and set the DecimalPlaces property for that field. Same for the Format property.

Thanks!

WaltW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top