Results 1 to 9 of 9
  1. #1
    napster75 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    7

    Help in Sequential Number that Restart to 1

    hi everyone,
    I have a problem in sequential number for example:
    tr001 consist of 5 records counting is 1,2,3,4,5
    tr002 consist of 3 records counting is 1,2,3
    and so on..

    below is the data:



    Click image for larger version. 

Name:	Capture1.PNG 
Views:	15 
Size:	13.6 KB 
ID:	35431

    I try to use DMax + 1 but I did not get the result I want.here is the code I used came from other forum.
    Code:
    If Me.NewRecord = True Then              
    Me.[CounterNo] = Nz(DMax("[TransID]", "Drawing"), 0) + 1           
    End If
    Field where sequential number stored - CounterNo


    Field where tr number stored - TransID
    Table - Drawing

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I don't think dmax will work for what you want, you probably want dcount

    there are hundreds of threads on this common subject, I'm surprised you haven't found one - look to the bottom of this thread and you will find a number there. Or there is this recent one

    https://www.accessforums.net/showthread.php?t=73616


    For the future, comments like 'I did not get the result I want' does not help us to help you. What result did you get?

  3. #3
    napster75 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    7
    thank you for the reply.. i saw that thread already but i did not get the result i want.

    I also try the query but it only count on how many records.
    Code:
    SELECT Drawing.DwgID, Count(Drawing.DwgID) AS CountofSeqNo
    FROM Drawing
    GROUP BY Drawing.DwgID;

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    thank you for the reply.. i saw that thread already but i did not get the result i want.
    hint
    For the future, comments like 'I did not get the result I want' does not help us to help you. What result did you get?
    And since I know it should do what you want, provide the code you actually used

  5. #5
    napster75 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    7
    Actually this is two table that link by TransID

    tblTrans
    PK TransID
    RefNo
    others details
    Click image for larger version. 

Name:	tblTrans.PNG 
Views:	11 
Size:	15.5 KB 
ID:	35436
    tblDrawing
    PK DwgID
    FK TransID
    CounterNo
    DwgNo
    others details
    Click image for larger version. 

Name:	tblDrawing.PNG 
Views:	11 
Size:	9.7 KB 
ID:	35437


    I have a form trans together with drawing subform
    what I did is that when I enter drawing no the CounterNo should start to 1

    I add the code in DrawgNo AfterUpdate
    Code:
    Private Sub DrawingNo_AfterUpdate() If Me.NewRecord = True Then Me.[CounterNo] = Nz(DMax("[TransID]", "Drawing"), 0) + 1 End If End Sub
    Sorry for the explanation I hope that you will understand what im trying to do.

    Thank you

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    best guess

    DCount("*", "Drawing","DwgID<=" & DwgID & " AND TransID=" & TransID) + 1

  7. #7
    napster75 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    7
    Ajax,

    this is amazing how did you do that. I tried so many times

    can you explain what happen. For what I understand is that the "*" means it will count all the records in drawing table and then compare to TransID?

    thank you very very much.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    the * just counts records, if you put a field name in, it counts all those where that field is not null - a subtle difference

  9. #9
    napster75 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    7
    I see..

    Thank you very much for your help.. I will mark this as solved.

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

Similar Threads

  1. Next sequential number
    By Jetski in forum Forms
    Replies: 11
    Last Post: 02-20-2014, 02:24 PM
  2. Sequential number problem
    By jfn15 in forum Programming
    Replies: 1
    Last Post: 06-21-2012, 09:33 AM
  3. Replies: 18
    Last Post: 05-15-2012, 03:44 PM
  4. Sequential number on subform
    By jpkeller55 in forum Access
    Replies: 8
    Last Post: 03-17-2011, 09:54 AM
  5. Restart auto number after deleting records
    By P5C768 in forum Database Design
    Replies: 1
    Last Post: 09-11-2009, 02:07 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