Computer Learning Zone CLZ Access Excel Word Windows

Education is a better safeguard of liberty than a standing army.

-Edward Everett
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to TechHelp    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Is New Record
Brian Crawford 
    
4 years ago
I have a HR DB and I would like to ensure that users CANNOT edit the BilletNumber of an existing BilletTbl record, but CAN type in a new BilletNumber for a new record.

I am not able to use VBA to determine whether I am in a new record.

I tried using this in the OnLoad event for the form:
    If Me.Form.NewRecord Then
        Me.BilletNumber.Locked = False
    Else
        Me.BilletNumber.Locked = True
    End If

For new records, I open the form with this code:
    DoCmd.OpenForm "Frm_BilletDetail"
    DoCmd.GoToRecord acDataForm, "Frm_BilletDetail", acNewRec

In the debugger, Me.Form.NewRecord is always 0 even on a new record, and the value of Me.BilletNumber is always the value of the first record even though it is blank on the form for a new record.  I am assuming that I may be using the wrong event or not setting a property before opening the form.
Adam Schwanz  @Reply  
           
4 years ago
I would do this in the on current event, It covers more if the record got moved with the form still open the event could re-fire.

Try this, I know I've used this before and it works.
   If NewRecord = True Then
          'stuff
    ElseIf NewRecord = False Then
          'other stuff
    End If
Adam Schwanz  @Reply  
           
4 years ago
Also you don't need the Me if your trying to interact with the form the code is on, BilletNumber.Locked will work fine
Brian Crawford OP  @Reply  
    
4 years ago
I found the issue. It was with the order of operations. The new record button first executes the DoCmd.OpenForm command, which triggers the OnLoad code of the form with the record pointer on the first record (i.e. NOT a new record), which is where the If statement runs with NewRecord being (always) False.  Then the second line  in the button DoCmd.GoToRecord executes AFTER the field is already locked (from the form's OnLoad code).

The solution was to remove the If statement from the OnLoad and lock the field by default
BilletNumber.Locked = True.  
Then move the unlock BilletNumber field as the third line in the New Record button code.
Adam Schwanz  @Reply  
           
4 years ago
You could also have just put it in the on current event instead, just FYI

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

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/17/2026 6:04:06 AM. PLT: 1s