Computer Learning Zone CLZ Access Excel Word Windows

Space is for everybody. It's not just for a few people in science or math, or for a select group of astronauts. That's our new frontier out there, and it's everybody's business to know about space.

-Christa McAuliffe
 
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 
Conditional Unlocking
Joseph O'Malley 
    
5 years ago
Hi Richard. I've watched the seminar all the way though and my database is much more secure now! Quick Question for you regarding unlocking fields. Like in your code I have none of the fields lock in my form and subform if the user is an admin or manager. If the user is in group 3 (a regular employee I have only certain fields unlock for them. However, thinking through it I would like even those fields to be locked for these users once the "record complete" combo box is clicked as "complete". What would the best way to go about this? Right now my code is identical to your from this video.
Adam Schwanz  @Reply  
           
5 years ago
You can just use an if statement for that. Just say something if user is in group 3 and record complete combo = complete then lock everything else if user is in group 3 and record compete combo <> complete, then lock just a few.
Adam Schwanz  @Reply  
           
5 years ago
Use your own field names but

If IsUserInGroup(3) and Combo = "Complete" Then
  'Lock Fields Code
ElseIf IsUserInGroup(3) and Combo <> "Compelte" Then
  'Lock Few Fields Code
End If
Adam Schwanz  @Reply  
           
5 years ago
Minus the spelling error there, Complete not Compelte, my fingers are just hitting what they want today LOL.
Joseph O'Malley OP  @Reply  
    
5 years ago
I have updated my code but the last if statement looking at group 3 just seems to disregard my second condition and not lock based on whether the combo box is marked complete, any ideas where I'm going wrong?

Dim ctl As control

   If UserUserInGroup(1) OR Is UserInGroup(2) Then
   'nothing

Else

  For Each ctl In Me
   If ctl.ControlType = acTextbox Or ctl.ControlType = acComboBox Then
      ctl.Locked = True
      ctl.BackColor = RGB(239,242,247) 'grey
   End If
   Next
  For Each ctl In Forms!MainFormName.SubFormName.Form!
     If ctl.ControlType = acTextbox Or ctl.ControlType = acComboBox Then
      ctl.Locked = True
      ctl.BackColor = RGB(239,242,247) 'grey
   End If
   Next
End If


If IsUserInGroup(3) And Forms!MainFormName.SubFormName.Form!CompleteStatus <> "complete" Then
'only lock certain fields from main form and subform inside the main form
Control1.Locked = False
Forms!MainFormName.SubFormName.Form!Control2.Locked = False

End If
End Sub


Joseph O'Malley OP  @Reply  
    
5 years ago
Ohh Actually thinking about it more this is form-level locking and the condition I added to say if a certain field with a record is marked as "complete" would be record-level locking which this probably wouldn't do, as any of my 305 records could be marked as complete or not complete. Would Anyone know how to accomplish this?
Juan C Rivera  @Reply  
            
5 years ago
Hi all, I used the tech help video showing a progress bar on the % of the form completed (extended cut). then I used a checkbox (hidden) if true lock (allow edits no) the form.  very simple Richard walks you through every step with the bar. If you don't have extended cut maybe Richard can allow it once so you guys can see what your missing :)
V/r
Juan

Adam Schwanz  @Reply  
           
5 years ago
You want Forms!MainFormName!SubFormName.Form!Control
Adam Schwanz  @Reply  
           
5 years ago
What do you mean record level locking? Record locking is something very different - https://599cd.com/blog/display-article.asp?ID=1659

That user level locking is what you want to do if you just want to stop people from editing any records that are marked "complete" with the form. If you have users that are going into tables directly that can circumvent this, I'd advise to get them out and onto the form.
Joseph O'Malley OP  @Reply  
    
5 years ago
Hi All I hate to be a bother but does anyone know what still might be wrong with my code? My fields in the subform are still not locking if the record is marked as complete and now I'm getting an error saying "return without Go-Sub". If I remove the "And Forms!Service.ServiceSubform.Form!Status <> "Complete" part of the If IsUserInGroup(3) statement I don't get that error but that is the past bit of functionality I am trying to tie into my db.

Joseph O'Malley OP  @Reply  
    
5 years ago
Private Sub Form_Current()

    Dim ctl As Control

    If IsUserInGroup(1) Or IsUserInGroup(2) Then
    'do nothing; don't lock fields for db committe and managers
    Else

        For Each ctl In Me

            If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
                ctl.Locked = True
            End If
        Next
        
        For Each ctl In Forms!Service.ServiceSubform.Form!
         If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
                ctl.Locked = True
            End If
        Next
        
End If

'testers: unlocking testing fields only if the record is not marked as complete
If IsUserInGroup(3) And Forms!Service.ServiceSubform.Form!Status <> "Complete" Then
'from parent form field unlock - nothing right now

'from subform field unlock
Forms!Service.ServiceSubform.Form!OnOffTrack.Locked = False

End If

End Sub
Adam Schwanz  @Reply  
           
5 years ago
Did you try the fix I told you earlier a few posts ago?

You want Forms!MainFormName!SubFormName.Form!Control

Change Forms!Service.ServiceSubform.Form!Status
To Forms!Service!ServiceSubform.Form!Status
Adam Schwanz  @Reply  
           
5 years ago
Does For Each ctl In Forms!Service.ServiceSubform.Form!  work for you?

I would thing that would need to be
For Each ctl In Forms!Service!ServiceSubForm
Adam Schwanz  @Reply  
           
5 years ago
Actually, just lock the subform much simpler. Don't need to do a loop for each control

Just do ServiceSubForm.Locked = True
Joseph O'Malley OP  @Reply  
    
5 years ago
Hi Adam, that you so much for your help. I switched the reference method for the subform controls as you suggested. I think that helped in some ways towards a few of my issues but I was still having the whole subform showing as locked when the status combo box was "not equal to"/ "<>" the phase "complete". I ended up switching some of the driving logic by setting that combo box's default value to " not complete" so then in the vba code I have it as when IsUserInGroup(3) then a nested IF statement saying to unlock the specific fields if the combo box is = to "not complete". So when the record is marked "complete" , which can only be done by a manger, the record will be locked for group 3. It' working like a charm now!
Adam Schwanz  @Reply  
           
5 years ago
Glad you figured it out

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: 5/6/2026 3:55:04 PM. PLT: 1s