Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Aug 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    customized 'autonumber' field (2000)

    Can you have a field automatically populate with an incrementing "number", that includes text and numbers?
    Ex: YMA-2004-001, next record would be YMA-2004-002, etc. Don't think autonumber type will work because it is a number data type. Any ideas?

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: customized 'autonumber' field (2000)

    To do this sort of thing, you need to create a custom autonumber function that stores the next number in a one-record table that you increment just before you save the new record. A true autonumber won't don anything else as it is a long integer (4 bytes).
    Wendell

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: customized 'autonumber' field (2000)

    Like Wendell said, you need to have a custom function that automatically assigns the next number. When I do this, however, I don't use another table to store the incrementing number. In my form's Before Update event, if it is a NewRecord I'll use the DMax function to get the highest number currently in the table, then increment it by 1.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    New Lounger
    Join Date
    Jan 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: customized 'autonumber' field (2000)

    I also write a code module to deal with simulating an autonumber. This is necessary for many reasons, such as allowing the user to specify a specific starting number for a range of invoices, etc.

    The "trick" is to write the code as tightly and efficiently as possible, so that you avoid the possibility of 2 or more people trying to save a record at the same time. I lock the table, grab the number from the table, increment it and store it backm in the table. Then I return it to the form or function that called the function requesting the new autonumber.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •