Results 1 to 8 of 8
  1. #1
    mahfuz_geo28 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Dec 2016
    Posts
    4

    Need to generate sequential number conditioned to other fields

    Hi, I'm trying to build a data entry form for an alumni database. I want to generate an unique ID for each alumni. The id is 8 digit alphanumeric. The last two digits is a sequential serial number which should restart from 01 for each new class and gender group within the class. Not sure if I'm making any sense, but would be delighted if could get some idea or simple VBA code. Thanks in advance.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Youre making work you don't have to do.
    add an ID column as autonumber. The table will create unique IDs for everyone. No programming.
    Create your 'homemade' ID later in a query.

  3. #3
    mahfuz_geo28 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Dec 2016
    Posts
    4
    Thanks for your reply. I already have an autonumber field for primary id. I'm actually trying to use a query to make my homemade id. The issue is - I don't know how to get the count of previous male students (for example) in a class, I would use that count + 1 as the serial no for the next entry. My level of VBA is zero.
    Last edited by mahfuz_geo28; 12-09-2016 at 12:20 PM. Reason: Clarity

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Why do you need a homemade id?
    What is its purpose?

    If you have an autonumber, and Name, Gender.... of alumni, please describe the rationale for the homemade id.

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Only the last 2 digits are unique (is 2 going to be enough?). You will enter class and gender on the form giving you the first 6 characters. At some point in time you want to get the new number depending on the sequence of entries on the form. On the second of those fields, in the AfterUpdate event of that field, select Event Procedure and add this VBA Code (change names as necessary):
    uniquenumber=CInt(DLookUp("Max(uniquenumber)","tab lename","Class='" & me!class & "' AND Gender='" & me!gender & "'")) + 1

  6. #6
    mahfuz_geo28 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Dec 2016
    Posts
    4
    The homemade id contains basic info about an alumni in it. For example just looking at the id one should be able to tell the alumnis batch #, gender, degree he received from the institution etc. Also, this is going to have a fixed number of digits. Auto numbering won't do that.

  7. #7
    mahfuz_geo28 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Dec 2016
    Posts
    4
    Two digits should be fine, there is always a maximum of 50 students in a class. Thanks for the code, I'll try it and let you know if I have question.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    just looking at the id one should be able to tell the alumnis batch #, gender, degree he received from the institution etc. Also, this is going to have a fixed number of digits
    Be very cautious with self-made codification-- it invariably comes back to bite you. Relational database works very well with a simple design approach---1 fact 1 field. My suggestion, rethink your scheme.

    If you are intent on some codification --design it, and test it (on paper) before programming. Trial and error is rarely a good strategy.
    Good luck with your project.

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

Similar Threads

  1. Auto generate sequential number
    By krai in forum Access
    Replies: 13
    Last Post: 08-17-2015, 06:05 AM
  2. Next sequential number
    By Jetski in forum Forms
    Replies: 11
    Last Post: 02-20-2014, 02:24 PM
  3. Replies: 18
    Last Post: 05-15-2012, 03:44 PM
  4. To generate sequential numbers in query
    By lizzywu in forum Programming
    Replies: 1
    Last Post: 03-02-2012, 12:01 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