FutureProgrammer
FutureProgrammer

Reputation: 45

Lock/Unlock All Forms

I have five forms that are used to input data into a database.

I want to know if I can lock and unlock all forms with the click of a button OR a pin code/password. The user is able to access all forms and add data to them but I would like there to be some form of security.

Within a new form, a username and password would be used to unlock all forms so that the user can enter data into them. Vice versa, a button should log the user out and lock all forms, preventing them from entering data into the forms.

The form looks like this There would be a button at the bottom that would close and lock all forms

I am using Access 2016

Is this possible? If so, how?

Upvotes: 1

Views: 1960

Answers (2)

Sergey S.
Sergey S.

Reputation: 6336

As I understand, you need to disable changing in forms and subforms. You can use form's properties .AllowEdits=False, .AllowDeletions=False and .AllowAdditions = False. If you change those properties, subforms also will be locked

To unlock just use True as a value for those properties. When user clicks Unlock button, procedure should ask PIN code. If entered correct PIN code, change .Allow* properties to True.

Upvotes: 1

Andre
Andre

Reputation: 27644

The easiest way to prevent editing is by setting the RecordsetType to 2 (Snapshot).

This should give you an idea, it locks/unlocks all opened forms:

Public Sub LockAllOpenForms(doLock As Boolean)

    Dim F As Form

    For Each F In Forms
        ' 2 = Snapshot = locked, 0 = Dynaset = editable
        F.RecordsetType = IIf(doLock, 2, 0)
    Next F

End Sub

To affect future forms, you need e.g. a public variable glbLocked set by your password form, and then in each data input form:

Private Sub Form_Open(Cancel As Integer)

    If glbLocked Then Me.RecordsetType = 2

End Sub

Upvotes: 1

Related Questions