Computer Learning Zone CLZ Access Excel Word Windows

Your most unhappy customers are your greatest source of learning.

-Bill Gates
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Database Security Seminar    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Locking Unlocking Fields
Joseph O'Malley 
    
5 years ago
I have a subform which is bringing in linked data from another table, when writting the vba code for locking up all the fields & unlocking based on GroupID can I set all of that in the parent form or do I have to go into to the subform and write the code in there as well for the corresponding fields?
Adam Schwanz  @Reply  
           
5 years ago
Just lock the entire subform at once on the main form. Don't need to go in and lock them individually.
Joseph O'Malley OP  @Reply  
    
5 years ago
How would I go about doing that?
Richard Rost  @Reply  
          
5 years ago
From the parent form just say:

SubformName.Locked = TRUE

So let's say you wanted to LOCK or UNLOCK the ContactF (which is a subform on CustomerF) depending on the status of the IsActive field, you would say this in the OnCurrent event:

Private Sub Form_Current()
    If IsActive Then
        ContactF.Locked = False
    Else
        ContactF.Locked = True
    End If
End Sub


It's that easy. Don't forget the same code in the AfterUpdate event for the IsActive field itself.
Joseph O'Malley OP  @Reply  
    
5 years ago
Thank you so much for the reply. would be okay with locking the whole subform at first but how would I go about unlocking specific fields within the subform based on GroupID? I apologize if I am missing something.
Richard Rost  @Reply  
          
5 years ago
Same thing, just a little more complicated.

ContactF.Form!FieldName.Locked = TRUE

Joseph O'Malley OP  @Reply  
    
5 years ago
Thank you so much for your help I really appreciate it. I'm getting an error and I was wondering if you can help he figure out were I'm going wrong

Private Sub Form_Current()
DIM ctl As Control

If ISUserInGroup(1) Then
Else
For Each ctl In Me

If ctl.ControlType = acTextBox or ctl.ControlType = acComboBox Then
ctl.Locked = True
End If

Next
For Each clt in Forms!MainForm.MySubform.Form!
If ctl.ControlType = acTextBox or ctl.ControlType = acComboBox Then
ctl.Locked = True
End If

Next
End If

If IsUserInGroup(2) Then
FieldName.Locked = False
Forms!MainForm.MySubform!FieldName.Locked = False

End If

End Sub


Adam Schwanz  @Reply  
           
5 years ago
Few things, maybe just my preference, but I like to just say 'do nothing if it's no code, easier to read.

If ISUserInGroup(1) Then
'do nothing
Else
For Each ctl In Me

This part has a spelling error, clt instead of ctl
For Each clt in Forms!MainForm.MySubform.Form!

These arent actually "FieldName" right? They're your real field names. Like ContactName.Locked = False etc, or do you have a field called fieldname?
If IsUserInGroup(2) Then
FieldName.Locked = False
Forms!MainForm.MySubform!FieldName.Locked = False

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Database Security Seminar.
 

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/9/2026 7:42:59 PM. PLT: 1s