Results 1 to 7 of 7
  1. #1
    msuguy71 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    10

    Question Increment custom value

    Hi all,

    Table: CCTLog


    Form: CCTLog
    Text box: Run#

    I am trying to increment a custom incident number in the form of YY-XXXX (ie: 13-0011). I need to increment the number part by 1 each time a new record is made, and the two digit year part needs to reflect the current year.

    I have the following formula in the default value entry of the data tab of the text box 'Run#'

    =Format$(Right$(Year(Date())),("[Run#]","CCTLog"),2) & "-" & Format$(Val(Right$(DLast("[Run#]","CCTLog"),4)+1),"0000")

    I get an error saying "The expression you entered has a function containing the wrong number of arguments."

    I can't figure out what I am doing wrong.

    Can someone help?

    Thanks,

    Rick

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    You are close. Two things.
    1) I would use "DMax" instead of "DLast".
    2) I put extra code to check for Null if the table has no data or when DMax returns Null value.

    =Format$(Right$(Year(Date()),2),"00") & "-" & Format$(Val(Right$(IIf(IsNull(DMax("[Run#]","CCTLog")),"0000",DMax("[Run#]","CCTLog")),4))+1,"0000")

  3. #3
    msuguy71 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    10
    Ifpm062010,

    Hi, thanks for the reply. Sorry about not getting back sooner. I put your formula in the default value entry but I am still getting #Error when starting a new record. Do I have to change another entry in the form properties? The property sheet text format is set to plain text and I left the input mask blank thinking what I had in there was causing my problem.

    Rick

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Do you want 0000 entered if this is the very first record of table? or should it be 0001?

    Part of the issue with IIf expression is that every part must be able to be evaluated, even the part that doesn't return value.

    The = sign is not needed in DefaultValue property.

    Do you want the sequence to start over each year?

    I do something very similar to this but I wrote a VBA function to handle.

    Generating a custom unique identifier is common topic in forum.

    http://forums.aspfree.com/microsoft-...ta-403208.html

    https://www.accessforums.net/access/...ers-21361.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    msuguy71 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    10
    June7,

    Hi, thanks for the reply. The sequence should start with YY-0001 at each year and increment by 1 each call. I think I had looked at similar posts before, and was not sure how to adapt it for my situation (I am still learning VBA). In the first link, do I put both sets of the VBA code in or do they each do the same thing in a different way. I think I can adapt the second one. I am going to work on that.

    I removed the = sign and I made the first 0000 into 0001 and I am still getting the error.

    Rick

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The first procedure in the first link is to demonstrate how I use the function that generates the unique ID. It is the function you can adapt to your situation. Where you use it is up to you.

    Not sure where your expression errors, but try:

    =Format$(Right$(Year(Date()),2),"00") & "-" & Format$(Val(Right$(Nz(DMax("[Run#]","CCTLog"),"0000"),4))+1, "0000")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    msuguy71 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    10
    Quote Originally Posted by June7 View Post
    The first procedure in the first link is to demonstrate how I use the function that generates the unique ID. It is the function you can adapt to your situation. Where you use it is up to you.

    Not sure where your expression errors, but try:

    =Format$(Right$(Year(Date()),2),"00") & "-" & Format$(Val(Right$(Nz(DMax("[Run#]","CCTLog"),"0000"),4))+1, "0000")
    So...I feel like an idiot. I mis-spelled CCTLog in my table and form names. I spelled it CTTLog by mistake. The first formula works great. Sorry about the confusion, and thanks for all the help everyone.

    Rick

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

Similar Threads

  1. Increment value in lookup Field
    By Rhemo in forum Access
    Replies: 5
    Last Post: 09-01-2012, 01:44 PM
  2. Increment Field Value
    By Malseun in forum Access
    Replies: 9
    Last Post: 02-03-2012, 04:55 AM
  3. Date Increment
    By James Tebb in forum Access
    Replies: 1
    Last Post: 04-11-2011, 11:40 AM
  4. Replies: 5
    Last Post: 11-12-2010, 12:10 PM
  5. Replies: 2
    Last Post: 12-08-2009, 01:19 PM

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