Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Coding Numbers
Michael Diaz 
    
3 years ago
What would be the best method to create a Case Number access with a Prefix followed by the year and then the Case Number i.e. ADA 23-0001 then have the number increase for every new file entered. As well as reset when the year changes?
Scott Axton  @Reply  
        
3 years ago
Michael
There are several videos on creating custom numbering schemes.
Check these out and see if one will work for you.  You might have to combine techniques but we're here to help if you hit a brick wall.

Sequential Numbers
Customer Codes
Sequential Annual Coding

Kevin Robertson  @Reply  
           
3 years ago
Here is an example. I put the code in a button for testing but you could call the code in an event so you don't need to click a button.

Private Sub btnGenerate_Click()

    Dim D As Date, CurrentYear As Long, PrevYear As Long
    Static CaseNum As Long, CaseNumStr As String
    
    D = Date
    CurrentYear = Right(Year(D), 2)
    PrevYear = Nz(DMax("Mid(CaseNumber, 5, 2)", "CaseT"), 0)
    
    If CurrentYear = PrevYear Then
        CaseNum = Nz(DMax("Right(CaseNumber, 4)", "CaseT", "Mid(CaseNumber, 5, 2)=" & PrevYear), 0)
    Else
        CaseNum = Nz(DMax("Right(CaseNumber, 4)", "CaseT", "Mid(CaseNumber, 5, 2)=" & CurrentYear), 0)
    End If
    
    CaseNumStr = "ADA " & CurrentYear & "-" & Format(CaseNum + 1, "0000")

    If IsNull(CaseNumber) Or CaseNumber = "" Then
        CaseNumber = CaseNumStr
    End If

End Sub


You can test the change of year by setting D to a static year. For example. #15/8/2024#
Michael Diaz OP  @Reply  
    
3 years ago
Thank you for your assistance with this matter. I have looked at all of the video's that were suggested and reviewed the code provided by Kevin, however I am having issues with getting the functionality to work the way I am looking for. I am attempting to have to CaseNumber automatically fill as a user creates a new case with the Prefix remaining the same depending on the case type they are entering and the number format for example of XYZ-YYYY0001 then the next being XYZ-YYYY0002 and so further based on the year the case was started.
Michael Diaz OP  @Reply  
    
3 years ago
Kevin, thank you for your assistance with this matter. the general functions are working great, the only part that does not seem to be work is the case number increasing when I add a new record. Any suggestions would be greatly appreciated. I have tried the following:
If CurrentYear = PrevYear Then
        CaseNum = Nz(DMax("Right(CaseNumber, 4)", "ADACaseT", "Mid(CaseNumber, 5, 4)=" & PrevYear), 0) + 1
    Else
        CaseNum = Nz(DMax("Right(CaseNumber, 4)", "ADACaseT", "Mid(CaseNumber, 5, 4)=" & CurrentYear), 0) + 1
    End If

However it has not caused the case number to increase when a new case is created.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/8/2026 9:30:01 PM. PLT: 1s