Results 1 to 6 of 6
  1. #1
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156

    Formatting a textbox (text data type) to add leading 0's

    Good morning, all!



    I'm working on a form to issue insurance policies, and trying to get it to create unique policy numbers each time. While I have most of the setup for that done, there is one field that is giving me fits. The truly unique part of each policy number is 3 digits; the rest can be repeated in other policy numbers. The field has to be text, because it must be combined with other parts to create the full policy number.

    The "PolID", as I'm calling it, needs to be 3 digits, with leading 0's where applicable (start with 001, and go up), unique, text, and unable to be manipulated by the user--completely system generated, and in place when the user opens the form to issue a policy (I do have code in place that should keep simultaneous users from getting the same #). I cannot for the life of me get those leading 0's to stick. I had them working yesterday, but work that I've done today has somehow shut it off, and I haven't been able to get them back. Right now, the textbox (ctlPolID) has the following in place:

    Default Value set to: =DMax("PolID","tblUwNew")+1
    (Basically trying to simulate auto# here, but without skipping values.)

    Code:
    Private Sub ctlPolID_AfterUpdate()
         'Format PolID to 3 digits with leading 0s.
        Me.ctlPolID = Format([PolID], "000")
    End Sub
    That code was working yesterday, but isn't today. I tried it on the form's load event, but then I didn't get anything to generate in the textbox at all.

    I've tried google, but not really finding things that apply to my situation (a lot of it is update queries for adding leading 0's later). Does anyone know how to do this?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The after update event is only going to fire if the user makes a change, and it doesn't sound like they are. Why not add the Format() function to the default value?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156
    I was afraid it was something like that. I'm still struggling a bit with syntax. How would I properly connect the Format to the existing expression? I had tried that first, but couldn't get it to work and switched to the code.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    =Format(DMax("PolID","tblUwNew")+1, "000")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156
    That's where I was going wrong! Was trying to tack the whole Format function onto the end. Derp!

    Thanks so much!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Formatting date to have leading zero for DAY
    By Praveenevg in forum Access
    Replies: 13
    Last Post: 08-20-2014, 01:27 PM
  2. Formatting numbers to have a leading zero
    By blacksaibot in forum Queries
    Replies: 7
    Last Post: 04-26-2014, 09:52 AM
  3. formatting a text box to show all data
    By mejia.j88 in forum Reports
    Replies: 8
    Last Post: 03-02-2012, 10:10 AM
  4. Replies: 2
    Last Post: 08-06-2011, 12:19 PM
  5. format of text data type
    By frcastro in forum Access
    Replies: 4
    Last Post: 06-23-2010, 09:36 AM

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