Results 1 to 10 of 10
  1. #1
    Beanie_d83 is offline Advanced Beginner
    Windows 8 Access 2013 64bit
    Join Date
    May 2016
    Posts
    73

    Using Dmax +1 Function From Query Total??

    Hi all,



    Is it possible/advisable to use the Dmax +1 function from the Total created from a query?

    I need to increment part numbers by 1 each time a part of a particular component type is created instead of using autonumber.

    Code:
    SELECT tbl_component_type.Component_Type_ID, tbl_parts.Part_Number, tbl_parts.Part_ID_PK
    FROM tbl_component_type INNER JOIN tbl_parts ON tbl_component_type.Component_Type_ID = tbl_parts.Component_Type_ID_FK
    WHERE (((tbl_component_type.Component_Type_ID)=[forms]![Copy Of frm_component]![cboSelect_Component_Type]))
    ORDER BY tbl_parts.Part_Number;
    Above is the SQL for the query, so my plan is to use the total generated by this and simply add 1??

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    I can't see a total result from that query.
    Why not use a autonumber - what is the problem with that?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Beanie_d83 is offline Advanced Beginner
    Windows 8 Access 2013 64bit
    Join Date
    May 2016
    Posts
    73
    Hi Minty,

    When I open the query in datasheet view, I can click the totals button on the ribbon (in the records portion) which displays the totals. It is this total I want to use to generate an incremental number.

    I can't use autonumber more than once in a table. I need to keep a record of all the parts we use in the manufacture of our products and these are identified by their "component type ID". Each component type (or group) have their own set of sequential part numbers so I need to generate an increment of one each time a new part of a particular component type ID is required.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    You would have to use an aggregate query(Totals Symbol in the query designer) to get the totals displayed in the Datasheet view then use that to get your DMax() value.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Beanie_d83 is offline Advanced Beginner
    Windows 8 Access 2013 64bit
    Join Date
    May 2016
    Posts
    73
    Ok, so would I use this to count the number of same component type ID records or use the Max value of the part number? I presume the latter as this is more relevant to what I'm doing!!

  6. #6
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Yes - create the query that returns the count of the item you want, then use either DLookup() to return that value and add one, or if you can simply use a DMax() you might do it a bit quicker.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    Beanie_d83 is offline Advanced Beginner
    Windows 8 Access 2013 64bit
    Join Date
    May 2016
    Posts
    73
    Right well so far so good! I now have the below code for the part number count which is returning the right results. I have noticed though that when the query runs, the first row in data sheet view has no ID number and a count of 1 which I find confusing. How can there be a count of an ID field that doesn't exist??


    Code:
    SELECT tbl_parts.Component_Type_ID_FK, Count(tbl_parts.Part_Number) AS CountOfPart_Number
    FROM tbl_parts
    GROUP BY tbl_parts.Component_Type_ID_FK;
    Click image for larger version. 

Name:	Count Query.PNG 
Views:	10 
Size:	13.1 KB 
ID:	33762

  8. #8
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    You must have a Partnumber record without an ID, or a Empty or ZLS string record somewhere.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  9. #9
    Beanie_d83 is offline Advanced Beginner
    Windows 8 Access 2013 64bit
    Join Date
    May 2016
    Posts
    73
    Ah yes I had a part with a missing type ID!

    Minty, thank you very much for your help

  10. #10
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    You are welcome!
    Good luck with your project.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. DMax function Help
    By AgentLozen in forum Access
    Replies: 3
    Last Post: 04-09-2018, 12:09 PM
  2. VBA DMax function
    By edson in forum Access
    Replies: 9
    Last Post: 01-31-2015, 10:11 AM
  3. ?? on DMAX function
    By eliotchs in forum Programming
    Replies: 4
    Last Post: 07-28-2014, 03:35 PM
  4. Dmax/Val function Problem
    By MintChipMadness in forum Programming
    Replies: 8
    Last Post: 08-13-2012, 08:50 AM
  5. using a qry to run a report with Dmax Function
    By mrjoshuaw in forum Access
    Replies: 6
    Last Post: 02-01-2012, 07:29 AM

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