Results 1 to 3 of 3
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828

    Question on function and how to format it?

    Hi all,
    A week or so ago one of the members here gave me some code to create a Unique # for my transactions in my db. (Code Below)

    I have two questions, One is I would like to format this to 10 digits such as 0000000001, Basically I want to have all be a 10 digit number and as the Unique # grows the 0's decreese
    Example... 0000000001, 0000000002, 0000000110, and so on... Need some assistance on how to make that happen?

    The second question is do I store the Unique # that is called for in my transaction table as a Num or ShortTxt?
    And if a Num would that be an interger, long integer, single....?

    Code:
    Public Function fnHeaderID() As Long
        
        Dim sSql As String
        Dim db As Database
        
        sSql = "INSERT INTO tblUniqueIDs (UniqueDate) Values (Now())"
        Set db = CurrentDb
        
        db.Execute sSql, dbSeeChanges
        fnHeaderID = db.OpenRecordset("SELECT @@IDENTITY")(0)
        Set db = Nothing
    
    
    
    
    End Function



    Thanks
    Dave

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    I recognise that...

    You can simply format the number for display on the form.
    Leave it as a Long Integer as joining on it for PK / FK purposes will be much more efficient.

    In the format in the format properties of the display control use "0000000000" or create a formatted version of it in the underlying query with a calculated field;

    MyDisplayRef : Format(YourFieldName,"0000000000")

    This means you still have access to the underlying number.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    Thank you Minty
    Helps A Lot
    Dave

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

Similar Threads

  1. function to format a name
    By ntambomvu in forum Programming
    Replies: 2
    Last Post: 11-08-2018, 11:42 AM
  2. Replies: 2
    Last Post: 07-19-2018, 12:05 PM
  3. Format Function Not Working
    By gameemaster in forum Queries
    Replies: 3
    Last Post: 05-13-2017, 02:28 PM
  4. Now Function Custom Format
    By DrJohn in forum Access
    Replies: 9
    Last Post: 03-16-2016, 09:51 AM
  5. Replies: 1
    Last Post: 03-18-2015, 09:17 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