How to add leading zeros to value in listbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jpstokes
    New Member
    • Sep 2011
    • 18

    #1

    How to add leading zeros to value in listbox

    I have a list box that contains 9 columns. I populate this listbox using a sql query. I want one of the columns in my listbox to show leading zeros. How would I accomplish this.

    For example, right now column with header 'Element' is showing numbers as 32...this should be 0032.

    I use the code below to populate the listbox:
    Code:
    Me.lbTasks.RowSource = "SELECT ID, DISCRETE_TASKS AS [Discreate Tasks], NETWORK, NWA AS [Activity], " & _
      "NWAE AS [Element], PLANNED_AMT AS [BAC], TOTAL_ACTUAL_COSTS AS [AC] , TOTAL_ASSIGNED_COSTS AS [EV], PLANNED_AMT AS [PV] FROM TASKS WHERE FUNDING_DOC_ID_FK = " & _
      fPrevious.lbFundingDocs & ";"
  • jpstokes
    New Member
    • Sep 2011
    • 18

    #2
    Problem solved...

    Code:
    SELECT ID, DISCRETE_TASKS AS [Discreate Tasks], Format(NETWORK, '000000') AS Networx, Format(NWA, '0000000') AS [Activity]...
      "Format(NWAE, '0000') AS [Element]
    This did it!
    Last edited by NeoPa; Oct 13 '11, 04:22 PM. Reason: Added mandatory [CODE] tags for you

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      I'll Demo for a Single Column (Element) in a Table (tblData):
      1. Original Data
        Code:
        Element
        1
        31
        35
        96
        121
        141
        159
        167
        220
        3456
      2. Statement populating RowSource of Listbox (lstTest)
        Code:
        Me![lstTest].RowSource = "SELECT Format([Element],'00000') FROM tblData;"
      3. Data display in lstTest
        Code:
        00001
        00031
        00035
        00096
        00121
        00141
        00159
        00167
        00220
        03456

      Comment

      Working...