Computer Learning Zone CLZ Access Excel Word Windows

Everyone should have their mind blown once a day.

-Neil deGrasse Tyson
 
Home   Courses   Seminars   Templates   TechHelp   Fast Tips   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Access >
TechHelp


Back to TechHelp
 

Is New Record Upload Images   Link  
Brian Crawford 
7 months 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
7 months 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
7 months 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
7 months 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
7 months 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, below.
 


Back to TechHelp Comments
 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to TechHelp
Get notifications when this page is updated
 
 
 
 

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
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
amicron@gmail.com
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn