Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Random Invoice Number
Jeffrey Kraft 
      
2 years ago
I recall a video where Richard used a random number for a Id number where he says the odds of duplicates is rare.  Well I'm creating or trying to create using ISO date format, and then 4 random numbers.  Stored in a string.

Code so far is:

Dim InvoiceDate As String
Dim RandomDigits As String

InvoiceDate = Format(TranDate, "yyyymmdd")
RandomDigits = FOrmat(Int((9999 - 1000 + 1) * Rnd + 1000), "0000") ' 4 digits

TrackingNumber = InvoiceDate + RandomDigits

Good news it works... bad news is those 4 digits seem to repeat too often in my "testing"  

I have 2 invoices in a row that end in 5800 I feel like I'm missing something to make it more random.
Kevin Robertson  @Reply  
          
2 years ago
Add Randomize to your code (below the variable declarations).

Random
Random Records
Jeffrey Kraft OP  @Reply  
      
2 years ago
It's the randomize function i think I'm looking for.
Juan C Rivera  @Reply  
             
2 years ago
Good day Y'all
If its an id look under the autonumber. You have another option under the general tap look for replication ID.  I think that is an option you can use or go get the ABCD databse where richard generats an entity number which is random but cheks to make sure its not also in the database.

Other option is what I use to track my projects I use julian date with Year and a four digit increment to show what the year last 2 digits day is was created and last four increase by one.  It also checks to see if the previous date is less than system date if true it resets the last four to 0000.
My format looks looks this 243640000 by looking at the number I can tell 24 is 2024, 364 is the day of the year and last four you can make 0 base or 1 base to increment on every project you add that day.
Matt Hall  @Reply  
           
2 years ago
Could you put the random number generator inside a loop that will also evaluate if that tracking number has already been assigned, through a DLOOKUP?   If it has, just rerun the loop.
Jeffrey Kraft OP  @Reply  
      
2 years ago
Sorry if I don't sound totally functional right now.  No coffee yet.

It's not an auto number.  

The Droid, I mean the code I was looking for was the randomizer.  

For reasons I don't want to get into I'm want the "Invoice" transaction to tracked as yyyyddmm and 4 random numbers from 0000 to 99999 (I'm never going to have more than 9999 "transactions" in a day - Heck I won't even hit 500 for a day).  Before I post the entry I do have it Dloopup the TransactionRegisterTbl (I use Tbl for Tables instead of T) and if it does find a match I get a msgbox telling me the numbers been used before, and then it tries again.    

The Randomizer from the vault with a small change does the trick and gives the "customer" the illusion I'm looking for.  

Now I'm either going to compile some Coffee!
Juan C Rivera  @Reply  
             
2 years ago
then you have the right idea throw it into a if statement have it check and if not used then pop it into a field.  I recomend a record set for speed.  Hope this helped.  

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: 8/21/2026 8:03:12 AM. PLT: 0s