Results 1 to 5 of 5
  1. #1
    Ultimateneo is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    19

    Incrementing a text field

    Hello I have at work a sharepoint list with an ID field.

    The next field is a Serial Number field that is stored as text even though it is a number field.

    I cant change the dat type fo the field as i didnt create the list



    I want to open the form and it is at new record for the ID field but gives me the next available serial number from the table.

    So it finds out the last serial number and then adds 1 to it. The share point list is accessed by many people so i need to make sure that no one else has taken that serial number before I save it, if it has gone to add 1 to that so it is the next serial number that hasn't been used before.

    Serial number example is 172345

    Any help would be appreciated, thank you for your time

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    You have a slightly difficult problem. IF you generate the number and a split second later someone else commits before you, you will either duplicate the number if the design permits or you will raise an error if not. The solution to that would be to create the number as the last thing in the operation but often a user needs that number at the start. The only solution to when the number is needed is to create it first and foremost, then it is locked in. That would allow you to continue entering data or park it for later. However, that number can never be released if the process is canceled. It can only be archived or otherwise flagged (e.g. Rejected or Canceled).

    Either way, you could use DMax function on the field as long as it will never contain alpha. There should be a means whereby that cannot happen.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Ultimateneo is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    19
    Hello I have so far

    Me.Serial_No_.Value = DMax("Serial_No_", "Serial Numbers") + 1

    Sadly they have a default text in the field Serial_No_, so i have to get the previous value and add 1 to it

    Is that possible ?

    Thank you

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Not sure I understand what you're reporting, or what the issue might be. DMax is a domain aggregate function (it operates on the domain, be that table or query). If the field or the form control has a value for the default value property, that should have no effect on the function because New Records are not actually in the table. They are only indications of what the new record will be when it is saved, and that depends on what other fields might be required. It can only return what is in the table, and what you see in the table view for a new record is of no consequence. By chance are you saying that if your maximum value is 172345, your next uncommitted (new) record in the table is showing 172346?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    you say the numbers are stored as text, in which case providing all the possible numbers have the same number of digits then dmax should work, but then you will need to convert it to a number to add 1 then convert back to text.

    If on the other hand you don't have the same number of digits then dmax will not work unless you convert it to a number first

    in text 2 is greater than 12

    suggest try using the clng function which converts text to a long number which should be fine if your maximum number of digits is 6

    DMax("clng(Serial_No_)", "Serial Numbers") + 1


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

Similar Threads

  1. Replies: 4
    Last Post: 09-01-2015, 05:38 AM
  2. Replies: 5
    Last Post: 04-16-2013, 07:24 PM
  3. Help With Incrementing field number
    By Neil2p in forum Programming
    Replies: 1
    Last Post: 03-18-2013, 08:17 AM
  4. Manual incrementing of a field
    By derisco1 in forum Programming
    Replies: 1
    Last Post: 08-11-2011, 05:15 PM
  5. Incrementing a field
    By Wayne311 in forum Programming
    Replies: 20
    Last Post: 01-20-2011, 06:21 PM

Tags for this Thread

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