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

How to create Format and DecimalPlaces properties?

Status
Not open for further replies.

WaltW

MIS
Jun 14, 2000
130
US
I'm using Access 2007, and I have VBA code in a form that creates a new table. For one of the fields in the table, I want it defined as Double, Fixed, with 2 decimal places. Default when the field is created is Double with Auto decimal places. In the Access help, it says that after you create the table/fields, Format and DecimalPlace properties are not automatically recognized, so you have to create them before you can change them. I've tried every variation of the CreateProperty method statement that I can think of, but can't get the property created. I'm obviously missing something that's probably simple. Can someone give me or guide me to the correct VBA command(s) to create a Format property and a DecimalPlaces property so I can change the defaults for this field?

Thanks for any help offered!

-Walt
 
How about:

Code:
    Set db = CurrentDb

    Set tdfNew = db.CreateTableDef("Test")

    Set fld = tdfNew.CreateField("aDouble", dbDouble)
    tdfNew.Fields.Append fld

     db.TableDefs.Append tdfNew
     
    Set prp = fld.CreateProperty("DecimalPlaces", _
        dbByte, 2)
    fld.properties.Append prp
    Set prp = fld.CreateProperty("Format", _
        dbText, "Fixed")
    fld.properties.Append prp

 
Normally, I consider this formatting, and don't bother doing such at table level, I'll specify it on forms/reports when needed. Short search in this forum, reveals at least two promising threads, check out thread705-1311540 and thread705-1127285.

BUT - my warning lights activates by this - having the interface creating objects that should have been created at design time is in my eyes a big no-no.

Could you perhaps detail a bit what you're after, then we can try to offer the best approach for it.

Roy-Vidar
 
Thanks very much for the responses. I had it coded pretty much like Remou suggested - turns out I had an ActiveX library as an active reference in the database that made things behave really screwy. Removing the ActiveX library reference cleared everything up.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top