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 
Unique number format for new record
Mubeezi Micah 

16 years ago
Dear Sally,

Somehow, i have failed to get your question off my mind. Having thought through again, its much safer in your database to have this primary key field (TXO-061510-0065) to autofill itself rather than the user to fill it. This will prevent nulls and duplicates.
First, you would need to have the last four digits of the TXO-061510-0065 to be an autonumber.

Then you will put an After Update event in the first field on the form where you will enter data. Why there?, because when this field gets "dirty" that is what forces the autonumber to appear (Lets call this field CustomerName),
Suppose your autonumber field is called ID.

You will then write the code below in the CustomerName After update event

Private Sub CustomerName_AfterUpdate()

SerialNumber = "TXO-" & Format(Date, "mmddyy") & "-" & Format(ID, "0000")
    
End Sub

Thats not all

To lock the SerialNumber field, first you would set Tab Stop = NO. Then write the following code in the on got focus event

Private Sub SerialNumber_GotFocus()

    'Block any possibility to edit the field
    If Not IsNull(SerialNumber) Then
    SerialNumber.Locked = True
    ElseIf IsNull(SerialNumber) Then
    SerialNumber.Locked = False
    End If
End Sub

I am pretty sure this should work perfect.

Best regards,

MICAH

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: 6/16/2026 1:33:57 PM. PLT: 0s