Results 1 to 3 of 3
  1. #1
    Weelmaa is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2012
    Posts
    3

    Setting Custom Field Format Property Problem

    Hello and thank you for viewing my post! I am new to this Forum. Any help with problem is much appreciated.

    Database Requirement: Automat the creation of a Table in Access with VB and setting a dbSingle type field's "Format" property to "000.0" as if a user was in the design mode and just typed "000.0" in the "Format" field property value textbox.

    It is already understood that the best practice is to not format values in a table. However, the person i'm making the database for is insisting that when a user enters a single digit in the table that it displays as 002.0 and not 2 (Can't get around this...I've tried)

    I've tried setting the format property of Field 2 by using the following code.

    Private Sub Command1_Click()
    Dim dbs As Database, tbl As TableDef, fld As Field, prop As Property
    Set dbs = CurrentDb
    '--Table Create
    Set tbl = dbs.CreateTableDef(Me.Text4)
    '--Field 1
    Set fld = tbl.CreateField("Vessel Name", dbText)
    tbl.Fields.Append fld
    '--Field 2
    Set fld = tbl.CreateField("Vessel ID", dbSingle)
    tbl.Fields.Append fld
    prop = fld.CreateProperty("Format", dbSingle, "000.0")
    prop.Value = "000.0"
    fld.Properties.Append prop
    '--Table Refresh
    dbs.TableDefs.Append tbl


    dbs.TableDefs.Refresh
    dbs.TableDefs.Refresh
    Application.RefreshDatabaseWindow
    End Sub

    The highlighted areas in RED is where I get an error message. Any help on this matter is greatly appreciated. Thank You!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Review http://www.utteraccess.com/forum/Set...ed#entry355808
    and
    http://answers.microsoft.com/en-us/o...d-c794d0e8fb97

    You probably need to set both the DecimalPlaces and Format properties. This works:

    Sub FixTable()
    Dim dbsT As Database
    Dim tdfT As TableDef
    Set dbsT = CurrentDb
    Set tdfT = dbsT.TableDefs("Table2")
    tdfT.Fields("DayID").Properties("DecimalPlaces").V alue = 1
    tdfT.Fields("DayID").Properties.Append tdfT.Fields("DayID").CreateProperty("Format", dbText, "Fixed")
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Weelmaa is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2012
    Posts
    3
    Thank you for the links....the links and your example helped me very much....Much Appreciated

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Setting visible property of subreport?
    By GaryElwood in forum Reports
    Replies: 1
    Last Post: 09-23-2011, 07:49 PM
  2. Replies: 3
    Last Post: 09-15-2011, 09:06 AM
  3. Over My Head: Custom Recordset Property
    By Drawn in forum Programming
    Replies: 1
    Last Post: 03-25-2011, 05:39 PM
  4. Format in Property Sheet
    By KevinMCB in forum Reports
    Replies: 8
    Last Post: 01-19-2011, 12:00 PM
  5. Replies: 1
    Last Post: 08-12-2010, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums