Results 1 to 8 of 8
  1. #1
    mooreb55020 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2018
    Location
    Minnesota
    Posts
    17

    Add 1 to the max value in a field based on the type


    All,

    First off thanks in advance. New to access and trying to build a list of products a company makes. However, the company has already built intelligence into the Item Codes. 01***** is a product line and 02***** is another. I have a list of all products and the product line they are in. What I'm looking to do is build a system that when a new product is added to a specific line it grabs the max value from that product line (this is a field in the table called ProdLineType) and adds 1 to it. The only other way I can think about doing this is to build a table for each product line and the query it all together. However, this makes building a bill of material for each one that much more difficult. Also, can I do that with text as they decided to have a leading zero on their product Item Code to distinguish between all 10 product lines they have? Again, thanks for your help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Generating custom unique identifier is a common topic. Search forum. Here is one discussion https://www.accessforums.net/showthread.php?t=23329

    Assume this is a text field and you want to increment the ***** part. Requires VBA to retrieve the max value based on product line, parse the string, increment, recombine parts. Although in your case, the parsing and recombining might not be needed if there are no alpha characters in the identifier.

    The first 2 characters identify product line? Only 99 product lines?

    Trick is handling generating first ID in a series. Is there a combobox on form for selecting product line? Consider:

    Format(Nz(DMax("ID", "Table", "Right(ID,2)=" & [Product]), [Product] & "00000") + 1, "0000000")
    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
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    Another post on sequential numbering...
    https://regina-whipp.com/blog/?p=704

  4. #4
    mooreb55020 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2018
    Location
    Minnesota
    Posts
    17
    June7,

    Yes there is a ComboBox and Field for selecting the Product Line. I have never used the code you wrote above. What you wrote seems fairly easy but I'm at a loss can you explain better on how this works? I'm assuming that if the product line is Colorant it should search for the last colorant product (lets say its 0100001) and make the next one 0100002. if the product is material (lets say the last one is 0200021) it will make the new one 0200022. could you explain the code a little more?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Suggest you research each function used and learn how they work individually. Then the nesting is like algebraic operation, work your way from inside to outside.

    Right()
    DMax()
    Nz()
    Format()

    These are all intrinsic to Access and VBA.

    However, if you have a field for product line, there probably is no need to also save this value into the product ID. Just increment the 5-digit ProductID. Simpler expression.

    Nz(DMax("ID", "table", "Product=" & [Product]),0) + 1


    Then concatenate ProductLineID with ProductID whenever needed for display purpose.
    =Format(ProductLineID], "00") & Format([ProductID], "00000")
    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.

  6. #6
    mooreb55020 is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2018
    Location
    Minnesota
    Posts
    17
    June7 you had it exactly right. i did a couple of instances where i used the SQL format and some with vba and it worked. Now I'm fighting another battle. I set up a form that has the property data entry set to "yes" so that it opens as a blank form. however, this causes it to add a new record from what i can see and then when i run my code it's adding 2 records for every entry. is there a way to either open the form and have it be blank without it creating a new record or is there a way to find the record the form just created and edit that record?

    i know this is off topic just thought i'd ask quick

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    DataEntry set to Yes does not cause a new record. Something else is. Most likely some code behind the form.
    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.

  8. #8
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    What's the code you are using to add a new record, that is most likely the issue.

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

Similar Threads

  1. Replies: 6
    Last Post: 01-13-2017, 08:54 AM
  2. Replies: 3
    Last Post: 01-09-2015, 05:48 PM
  3. Field Type of type-Double/Float
    By McArthurGDM in forum Access
    Replies: 3
    Last Post: 12-10-2014, 01:54 PM
  4. Replies: 2
    Last Post: 07-14-2014, 01:31 AM
  5. Replies: 7
    Last Post: 02-25-2012, 07:32 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