Results 1 to 8 of 8
  1. #1
    redpenner is offline Novice
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    23

    Increment number in field when another field updated

    I have a table BILLING which I enter data into using a form in datasheet view. Two of the fields are BILLDATE and INVNUMBER. What I would like to do is automatically enter a new INVNUMBER (calculated as the previous maximum invoice number + 1), but not until the BILLDATE is filled in. I don't want to enter a number when the record is first added, because they are added well in advance of actual billing. I want this to be a default value, but need to be able to modify it if needed.

    I can calculate the incrementing invoice number all right, but not sure how to code in (or create macro) to calculate and save it when a value is entered in BILLDATE. (I'm still just learning how to use Events to trigger actions.)



    Can anyone suggest a good, preferably simple, way to go about this?

    Edited to add: I am using Windows 7 now, not Vista - should have updated before posting
    Last edited by redpenner; 10-29-2015 at 02:38 PM. Reason: Change version of Windows

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Try BillDate AfterUpdate event. Probably don't want to increment the InvNumber every time BillDate is edited for the same record. So try:

    If IsNull(Me!InvNumber]) Then Me!InvNumber = DMax("InvNumber", "tablename") + 1
    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.

  3. #3
    redpenner is offline Novice
    Windows 7 32bit Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    23
    Tried it, got a Syntax Error.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Sorry, typo - unnecessary ] after InvNumber.
    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
    redpenner is offline Novice
    Windows 7 32bit Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    23
    Now getting a type mismatch. It occurred to me that my INVNUMBER field is a text field (because back a few years we had an alpha prefix on our invoices). Do I have to extract a numeric string or something to get the +1 to work?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Yes, will have to extract numeric part.

    Is there only one character as the alpha prefix? The full value is always same number of characters? Provide examples.

    Generating custom unique identifier is a common topic. Here is one https://www.accessforums.net/access/...ber-20506.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.

  7. #7
    redpenner is offline Novice
    Windows 7 32bit Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    23
    Most older values are of the format NC2011178, a few have an alpha character following (NC2011178a) and more recent values are like 20140021, some with the same alpha suffix. I'm thinking I should just strip off the prefixes and suffixes and put them in separate fields, since most of those are historic but we occasionally still do have the suffix alpha. I can concatenate the 3 fields for the invoice or any other kind of reporting. Since I have 4 different formats to deal with, it seems like the wise thing to do, and not too much work for me on a slow day like today.

    I think I'll go ahead and do that, then try your solution again.

  8. #8
    redpenner is offline Novice
    Windows 7 32bit Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    23
    Well, it works very well! When I fill in a BILLDATE, the correct INVNUMBER fills in, and I can edit or delete it if I want. And I'm much happier about my three-part invoice number solution.

    Thank you for the code! I appreciate your time and help.

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

Similar Threads

  1. Replies: 1
    Last Post: 10-16-2013, 09:41 AM
  2. Replies: 3
    Last Post: 06-21-2012, 05:25 PM
  3. Replies: 15
    Last Post: 05-17-2012, 01:12 PM
  4. Replies: 5
    Last Post: 11-12-2010, 12:10 PM
  5. How to Increment A Number Field
    By Advanced in forum Programming
    Replies: 3
    Last Post: 01-27-2010, 02:36 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