Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    bennyhana88 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    15

    Sequential Number by group in a field

    Hello all. I have access 2010 and 2013 between work and home. I need a solution for my problem that I can use interchangeably between both platforms.

    Here is the problem, I have a table like the one below. I need to Auto Sequence based on JobIDOne in the field that says sequence in the manner that I've typed. Hand typing is not an option because by table will be updated regularly. All other fields are updated via a form. I need a either a macro or VBA solution that can reconcile this, preferably through the table. Note, I do not want to use a query to create this sequencing or SQL language as I do not know how to write SQL commands.

    I know it can be done but I've seen about a thousand ways to do it that I haven't been able to modify for my specific table.

    DateOne TimeIn JobIDOne InitialsOne Dates Worked One Sequence
    7/17/2015 6:45:10 PM 12345 AR 7/17/2015 1
    7/17/2015 6:45:17 PM 12346 BVD 7/17/2015 1
    7/17/2015 6:45:35 PM 12345 AR 7/17/2015 2


    7/18/2015 4:15:47 PM 12345 AR 7/18/2015 3
    7/18/2015 4:15:53 PM 12346 BVD 7/18/2015 2

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Generating custom identifier is a common topic. If you want to save this value into table, will require code that looks up the most recent Sequence for a group and increments it. Otherwise, this sequence can be generated 'on-the-fly' in a report by using textbox RunningSum property (only available on report, not form) and report Sorting & Grouping feature. Review http://allenbrowne.com/ranking.html

    Also https://www.accessforums.net/forms/a...ing-23329.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.

  3. #3
    bennyhana88 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    15
    I've seen this kind of code before but I don't know how to apply it to my table. I need table specific assistance. I'm new to access and I'm learning VBA at a snail's pace. Is there an example of the code using my example table fields that I could utilize or that anyone would be willing to produce?

    I'm sorry if I'm asking a lot, all of these codes get really confusing when they aren't using your table.

  4. #4
    bennyhana88 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    15
    P.S. yes I want to save this in a table, not a report.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Since your sequence is a number (not a mix of text and digits), might just be able to use DefaultValue property of textbox. Something like:

    DMax("Sequence", "mytable", "JobIDOne=" & [JobIDOne]) + 1

    The real trick is figuring out where to put this expression. Possibly in a subform that is linked to main form on JobIDOne PK/FK fields. Don't really know your db design well enough.

    However, issue with generating custom identifier is the risk of multiple users generating and attempting to save the same identifier. Minimize this risk by immediately committing the record to table. Now this adds complication if the user is allowed to abort data entry of a new record. Managing this to assure data integrity can get rather complicated.

    That is for new record data entry. If you want to update a table full of existing records, that is another issue.
    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
    bennyhana88 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    15
    This expression will add a new number to the Sequence field or the JobIDOne Field? JobIDOne is my group field that identifies how I want my sequence field to run. The numbers need to increase in the sequence field based on the number entered in the JobIDOneField. JobIDOne is the ID number for a particular employee. I'm just trying to count the number of times an employee clocks in through my database. Would it be helpful if I uploaded my db so you can see the form, tables and queries to get a better understanding of my end goal?

  7. #7
    bennyhana88 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    15
    Attached is the access file for my DB. Hopefully it works.
    Attached Files Attached Files

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    The expression is intended to increment the Sequence field, the JobIDOne field is in the WHERE CONDITION argument.

    Why does the table have field name TimeIn but no TimeOut?

    Perhaps this will be helpful http://allenbrowne.com/subquery-01.html#AnotherRecord
    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.

  9. #9
    bennyhana88 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    15
    I placed time out in a second table and figured if I had code that I could apply to the time in table I could make small changes to apply it to the time out table. I put them in two different tables so I could run a query and compare time in and time out in the same line. If I had them in the same table I would have to right more code to fill in a null value and it seemed like a bigger headache to do it that way.

    You'll also see two date columns; one has a time stamp but the other just carries over the date value out of the time stamp so I can do my analysis in an excel pivot table and sort by date.

  10. #10
    bennyhana88 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    15
    P.S. This is the error I get when updating the default value in sequence with the first equation you gave me.

    Click image for larger version. 

Name:	Error.jpg 
Views:	21 
Size:	112.2 KB 
ID:	21358

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    I've never actually tried that technique and apparently DefaultValue property cannot handle domain aggregate functions. Use the expression in VBA code in an event. Try the form Current event.

    If Me.NewRecord Then
    Nz(DMax("Sequence", "mytable", "JobIDOne=" & [JobIDOne]),0) + 1
    DoCmd.RunCommand acCmdSaveRecord
    End If

    Review http://www.baldyweb.com/CustomAutonumber.htm

    If you had one table would need code to find the last record with a time in value but time out was still null and then populate the time out so each record would have a time in and time out pair. That is a conventional approach and I recently assisted another poster with that schema.
    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.

  12. #12
    bennyhana88 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    15
    Unfortunately the second line of that command gives me an error (Expected: =)

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Sorry, forgot.

    Me!Sequence = Nz(DMax("Sequence", "mytable", "JobIDOne=" & [JobIDOne]),0) + 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.

  14. #14
    bennyhana88 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    15
    Still having trouble getting it to work

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    What is the 'trouble' - error message, wrong results, nothing happens?
    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.

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

Similar Threads

  1. Replies: 4
    Last Post: 06-24-2014, 10:49 AM
  2. Next sequential number
    By Jetski in forum Forms
    Replies: 11
    Last Post: 02-20-2014, 02:24 PM
  3. Sequential number problem
    By jfn15 in forum Programming
    Replies: 1
    Last Post: 06-21-2012, 09:33 AM
  4. Replies: 18
    Last Post: 05-15-2012, 03:44 PM
  5. Sequential number on subform
    By jpkeller55 in forum Access
    Replies: 8
    Last Post: 03-17-2011, 09:54 AM

Tags for this Thread

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