admin lock form - read only with password question???

GoodLife22

Registered User.
Local time
Today, 10:01
Joined
Mar 4, 2010
Messages
86
I have a main form with a combo box drop down with a list of my clients. You select the client then the subform will show the information for that client.

I want to set the subform to open in READ-ONLY mode so my users cannot change any data for most of the fields. However there are a handful of people who need to be able to make changes to the data so I want to add a button that will grant them admin access if you would. If they click that it prompts them for a password, if correct all read-only goes away. Then they can click the same button again and the locked down fields are once again set to read-only. So a simple lock/unlock feature.

Can this be done? If so what is the best way to attack this?

Thank you all.
 
In the Open event of the sub form, set the Allow Additions and Allow Edits properties to False;

Code:
Private Sub Form_Open (Cancel As Integer)
 
With Me
     .AllowAdditions = False
     .AllowEdits = False
     .YourCommandButton.Caption = "Unlock"
End With
 
End Sub

In the Click event of the command button, change the caption of the button and modify the same properties to either True or False depending on the Caption;

Code:
Private Sub YourCommandButton_Click()
 
With Me.YourCommandButton
     If .Caption = "Unlock" Then
          Me.AllowAdditions = True
          Me.AllowEdits = True
          .Caption = "Lock"
     Else
          Me.AllowAdditions = False
          Me.AllowEdits = False
          .Caption = "Unlock"
     End If
End With
 
End Sub
 
thank you so far. I looked at those code and it looks like it should work perfect but it doesn't.

I created a new button and simply named it: "YourCommandButton" so I could simply copy and paste the rest of your code exactly as it is.

When I open my form I cannot make any changes in the sub-form so the first section Form_Open works fine. I see my button with the "Unlock" caption and if I click it sure enough I CAN start making changes. So the AllowEdits = True works and it does change the caption to "lock"

When I click the button a second time to lock it back down the caption does go back to "Unlock" however I can still make changes to the info in the form.

Any thoughts?
 
OK I made one small change to

Code:
Private Sub YourCommandButton_Click()
 
With Me.YourCommandButton
     If .Caption = "Unlock" Then
          Me.AllowAdditions = True
          Me.AllowEdits = True
          .Caption = "Lock"
     Else
          Me.AllowAdditions = False
          Me.AllowEdits = False
          .Caption = "Unlock"
          Me.Refresh
     End If
End With
 
End Sub

And it now seems to work. Is there anything wrong with doing it this way and adding the refresh?
 

Users who are viewing this thread

Back
Top Bottom