Results 1 to 4 of 4
  1. #1
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038

    Need "leading zeros" in concated field (on form)


    Experts:

    I need assistance with formatting a concatenated field in order to include leading zeros. Attached sample database includes four tables and one form.

    Upon opening the database, please reference table "T01_Billets". Here, field [Ra_BIN] is of data type = number and formatted as "0000000". Thus, in the table view, leading zeros are added to show values as either, e.g., "0001234" or "9990001". This 7-digit format is desired for this field.

    Now, in the form, the first combo (Control Source = "BilletIDfk") includes concatenated values of the numeric field [Ra_BIN] and text field [Ra_BIN_Title]. The row source for the combo is as follows:

    Code:
    SELECT T01_Billets.BilletIDpk, [Ra_BIN] & " | " & [RA_Billet_Title] AS Ra_BIN_Title FROM T01_Billets ORDER BY [Ra_BIN] & " | " & [RA_Billet_Title];
    Unfortunately, the leading zeros of [Ra_BIN] are lost during the concatenation process. That is, instead of showing the **desired output** = "0001234 | Operator", the combo displays, e.g., "1234 | Operator" instead.

    I have tried to change the rowsource to the following format:
    Code:
    SELECT T01_Billets.BilletIDpk, Format([Ra_BIN],0000000) & " | " & [RA_Billet_Title] AS Ra_BIN_Title FROM T01_Billets ORDER BY [Ra_BIN] & " | " & [RA_Billet_Title];
    But again, the incorrect format (i.e., losing the leading zeros) is displayed and drops the leading zeros for any values less than 7 digits.

    My question: How do I change the rowsource to force the output to be either, e.g., "0001234 | Operator" or "0002000 | Accountant"? Naturally, values that are 7 digits in length shouldn't be impacted by this. So, the current display of "9990001 | Planner" is perfectly fine.
    Attached Thumbnails Attached Thumbnails Field in Question.JPG  
    Attached Files Attached Files

  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,518
    This worked for me as the combo row source:

    SELECT T01_Billets.BilletIDpk, Format([Ra_BIN],"000000") & " | " & [RA_Billet_Title] AS Ra_BIN_Title FROM T01_Billets ORDER BY Format([Ra_BIN],"000000") & " | " & [RA_Billet_Title];
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,038
    Paul -- excellent... didn't know about the 2nd formatting (after the order). Again, thanks... 'appreciate your help!

  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,518
    Happy to help! I'm not sure that affects it, that got added automatically when I changed it in the field line. It seems to work without that in the sort order, though of course then the sort isn't correct.
    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. Replies: 19
    Last Post: 03-09-2017, 09:48 AM
  2. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  3. Issues with leading zeros in a form field
    By apetriella in forum Forms
    Replies: 2
    Last Post: 02-10-2015, 11:27 AM
  4. Replies: 7
    Last Post: 09-20-2014, 06:48 PM
  5. Replies: 3
    Last Post: 04-22-2013, 06:08 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