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 Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Sequential numbers only to 10
Kim Nielsen 
      
3 years ago
Hi I have tried to figure out why my custom numbers only go up to 10. The code is designed to restart the sequence every month, for example 202303-1.. 202304-1. However for some reason the numbering max out at 10, then it doesnt count any higher. What have i missed n this code? I could get up to 4000 records in a month. Help...much appreciated

Private Sub Form_BeforeInsert(Cancel As Integer)
    Dim vlast As Variant
    Dim NextRec As Integer

    Me.FillDate = Format(Date, "dd-mmm-yyyy")
    Me.RecYear = Format(Date, "yyyy") & Format(Date, "mm")
    vlast = DMax("SeriesNum", "1a-FillDetailsT", "RecYear='" & Me.RecYear.Value & "'")
    
    If IsNull(vlast) Then
    NextRec = 1
    
    Else
    NextRec = vlast + 1
    End If
    
    Me.txtSeriesNumber = NextRec
    Me.txtRecID = Me.RecYear & "-" & Me.txtSeriesNumber
    
End Sub
Kevin Yip  @Reply  
     
3 years ago
If "SeriesNum" is a string, then a string value of "9" would be considered greater than a string value of "10".  When you reach "10", your DMax would still return "9" as the max, and you would keep getting "10" as the next value.  That's my guess for what is happening.  

String comparisons are done by comparing each character of two strings from left to right.  "9" is a greater than "100000" because looking at them from left to right, the first character of "9" is greater than the first character of "1".
Kim Nielsen OP  @Reply  
      
3 years ago
In the table 1a-FillDetails the following fields are in place as follows:
FillDate = Date of the fill usually todays date formatted dd-mmm-yyyy  Date/Time
RecYear = Record year formatted as "yyyy"-"mm" is a ShortText
SeriesNUm = the next number in the series based on RecYear is a shortText
All this goes into the FDRecordID formatted as 202303-1, 2, 3, etc  then 202304-1, 2, 3 etc
So if i read this correctly, the "SeriedNum" should be a number format?

Thank you
Kevin Yip  @Reply  
     
3 years ago
SerialNum should be a numeric if you want to retain the same VBA code.  If you want to keep SerialNum as short text, you can modify your VBA code slightly to this:

     vlast = DMax("Val(SeriesNum)", "1a-FillDetailsT", "RecYear='" & Me.RecYear.Value & "'")

The Val() function above converts any string that looks like a number into an actual number.  Therefore, DMax() will return the numerical max.

Caveat: Access defines "looks like a number" as having a numeral as the first character.  Hence, Val("2") and Val("2abcdefghij") both return the numeral 2.  But Val("a2") will return 0 instead.  Val() returns 0 for any string that doesn't "look like a number."

My suggestion is to actually change SerialNum to a numeric field.  Any field that can only be numeric (and more importantly, must be numeric in order to work, as in your case here) should be a numeric field.

Kim Nielsen OP  @Reply  
      
3 years ago
Kevin; Thank you so much. I changed the field to a numeric and yes it worked and is working as intended. Hugely appreciated.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access 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 8:44:58 PM. PLT: 0s