Results 1 to 4 of 4
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    Trying to pad leading zeros in export

    I am exporting to a flat file from a query and need to pad zero's

    I have tried .VarCarNumber = Nz(rs!Format([CarNumber], "000000"), "") but it says external name not defined.

    I am using VarCarNumber As String * 6 when i declare the variables.



    Currently with .VarCarNumber = Nz(rs![CarNumber], "") it exports like TCIX6302 TE170403492190R315 - as you can see it is left aligned and has no leading zero.

    Any ideas how I can make this work best. When i try to do it in the query it wont allow CarNumber: Format([CarnUmber],"000000"), it says Circular reference caused by alias "CarNumber in query definitions select list.

    Thanks

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Are you trying to do this in a query or VBA?
    If VBA, please post your VBA code.
    If in a query, you wouldn't use a "rs!" reference in front of the Format function.

    Also, what is the Data Type of CarNumber? The Format function only works on numeric fields, not text fields.
    What is the total length of the desired result?

  3. #3
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    I use a query and export it using VBA

    I was able to get it to work by formatting the output after TextFile.WriteLine I used Format(.VarCarNumber, "000000")

  4. #4
    rkeifer is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2019
    Location
    Mays Landing, NJ
    Posts
    3
    Here is a UDF which also works


    Function PadLeft(parmString As String, ParmChar As String, ParmLen As Integer) As String
    '--------------------------------------------------------------------------
    ' parmString - string you want padded
    ' parmChar - character used for padding left
    ' parmLen - final length of returned string
    '--------------------------------------------------------------------------
    If Not IsNull(parmString) Then
    PadLeft = String$(ParmLen - Len(Trim$(parmString)), ParmChar) & Trim$(parmString)
    Else
    PadLeft = ""
    End If

    End Function

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

Similar Threads

  1. Delete Leading Zeros
    By KathyCo in forum Queries
    Replies: 4
    Last Post: 11-01-2016, 11:59 AM
  2. Do not add leading zeros
    By phifer2088 in forum Access
    Replies: 5
    Last Post: 03-02-2015, 10:05 AM
  3. Trying to get leading zeros to show
    By Pegasus_Angel in forum Access
    Replies: 3
    Last Post: 10-25-2012, 11:40 AM
  4. Leading Zeros
    By dirtbiker1824 in forum Access
    Replies: 1
    Last Post: 03-14-2011, 02:16 PM
  5. leading 'Zeros' in data
    By wasim_sono in forum Forms
    Replies: 3
    Last Post: 04-06-2009, 11:57 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