Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    chudok01 is offline Novice
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    7

    Counter based on data category

    I am trying to get a counter to count based on data. column 1 shows what I am needing.



    Click image for larger version. 

Name:	Counter.png 
Views:	31 
Size:	11.6 KB 
ID:	51906

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,571
    Have you tried Count() and GroupBy ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    Need to know more - for example, does the order of the second column matter? I.e in the first group does t matter if 17358 is the third record in the group? Or could it be in a different position?

    Reports have the functionality you require but if this is not for a report then the answer to the above question will dictate which direction a solution might take

  4. #4
    chudok01 is offline Novice
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    7
    Quote Originally Posted by CJ_London View Post
    Need to know more - for example, does the order of the second column matter? I.e in the first group does t matter if 17358 is the third record in the group? Or could it be in a different position?

    Reports have the functionality you require but if this is not for a report then the answer to the above question will dictate which direction a solution might take
    Yes the second column needs to be in that same order. This data has to do with recreating the line key for Bill of material. The first column would be the Header item and then second row are the item components that make up this Header BOM. Even if the column is not there I mainly need the count on the first column.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    Yes the second column needs to be in that same order.
    This is not excel, in databases you need a sort order so you need to include a field that specifies that order as simply sorting on it would change it because it is text and sorting text ascending would put the purely numeric values before the none numeric values.

    A possible alternative is to use a rownumber function.

    See this link and take a look at the code which has such a function

    https://www.access-programmers.co.uk...report.326715/

  6. #6
    chudok01 is offline Novice
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    7
    Quote Originally Posted by Welshgasman View Post
    Have you tried Count() and GroupBy ?
    Yes I have, not working for what I need

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    One set has numbers descending (17359, 17358) another set has numbers ascending (15227, 15235). And then numbers are between two values beginning with alpha. This will require complicated code to calculate a sort value. What are the rules for this ordering?
    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
    chudok01 is offline Novice
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    7
    Click image for larger version. 

Name:	sample from Excel.png 
Views:	22 
Size:	46.8 KB 
ID:	51914
    Quote Originally Posted by June7 View Post
    One set has numbers descending (17359, 17358) another set has numbers ascending (15227, 15235). And then numbers are between two values beginning with alpha. This will require complicated code to calculate a sort value. What are the rules for this ordering?
    Attached is a sample of what I can do in Excel. I really need to do the same concept in Access. The items in column B will be sorted and together. Yes we have numerical and alpha in our item numbers. Just feeling that this is really not feasible in Access easily.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,571
    Have a look here
    https://www.youtube.com/watch?v=2yj6x5E4Z_0

    You need a sequential field of some sort to compare against, just as you are doing in Excel.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    But what dictates that the rows are in that order to begin with?

    Records in a db table have no inherent order (bolts dropped in a bucket).

    Order of Details values does not follow any intrinsic sorting rules (alpha or numeric). If Details must be in order shown, then yes, this is not easily done. Even Excel has to follow rules when sorting rows.
    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.

  11. #11
    chudok01 is offline Novice
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    7
    I am able to use something like this in excel and it works great =IF(B2=B1,A1+1,1)
    I need something as simple as this in Access. These are grouped together in Access so I could get the same result. So if Access cannot do this - then I need to stick with excel. I was just hoping I could do this inside of Access.

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    I need something as simple as this in Access.
    as stated in the thread, you need to be able to specify an order - just as your excel file is ordered (you would not get the result you required without it)

    So to answer your question, it is simple - providing you have the appropriate data to create the order. In your case, you don't have the appropriate data since in post #1 the details column is in random order after the based on column and in post #4 you have stated the order has to remain the same. Perhaps you have a PK or a timestamp field which would do that.

    In post #8 you provide different data and no indication as to whether an order has been applied

    The rownumber functions I provided a link to in post #5 provides the same functionality as your excel calculation - i.e. works on the basis of the first column (your column B) changing value to reset the counter.

  13. #13
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    What you need is a windowing function like ROW_NUMBER() or RANK(). I know how to use them in SQL but not the Acces syntax. Maybe someone else on this forum can give you the Access syntax.

  14. #14
    chudok01 is offline Novice
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    7
    CJ_London,

    I am sorry for any confusion. in post one, it does not matter what is in the details column, what I need a counter in is the column called "item counter based on". I need to focus on that field. Yes I did post other data just trying to get the focus on the column that I need to count.

    I did look at your post - but it appears that these are on a form. I will need to export the results to excel for data upload into an ERP system. Is there a way to do that with form data?

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,571
    Quote Originally Posted by NoellaG View Post
    What you need is a windowing function like ROW_NUMBER() or RANK(). I know how to use them in SQL but not the Acces syntax. Maybe someone else on this forum can give you the Access syntax.
    Such a function is in that link that @CJ_London posted?
    All the O/P has to do is use that in his query.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form Based on SKU Category
    By HansBades in forum Access
    Replies: 4
    Last Post: 08-22-2022, 11:07 PM
  2. Replies: 8
    Last Post: 10-07-2018, 05:24 PM
  3. Replies: 1
    Last Post: 01-22-2016, 04:36 AM
  4. Replies: 27
    Last Post: 12-02-2015, 06:09 PM
  5. Replies: 5
    Last Post: 05-10-2014, 09:24 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