UNDO to protect contents

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using Access 2002.

I have a main form with 2 sub forms. I would like the user to not be able
to make changes to the main form or the subforms unless they are the
"Author". I thought I figured it out, but......... the UNDO action is
taken, message box is shown correctly, user clicks ok, and then the user can
edit/change and navigate to any field. It works well on the FORMS's before
update, but I want the user to see the msgbox as soon as they type (if they
are not authorized). Here is my code in the ON DIRTY event, any idea?

'If the user is not the Analyst and not an Author msgbox will display

If Me.cbo_Analyst <> Forms![Temp].Modify_By Then

If Forms![Temp].[strAccess] <> "Author" Then

Undo
MsgBox "You do not have Access to modify this Project"
Exit Sub
Else


Me.Modify_Date = Date
Me.Modify_By = Forms![Temp].[Modify_By]
Forms![Temp].[SR] = Me.SR


End If
End If
'********************************************************
 
I have a main form with 2 sub forms. I would like the user to not be able
to make changes to the main form or the subforms unless they are the
"Author".

I'd suggest setting the Form's AllowUpdates event to True or False in
its Load event, based on the identity of the author and the user.

John W. Vinson[MVP]
 
Here is a cool trick that you don't have to change data bindings at all

Enter an * in the tag property of the controls you want to lock/un-lock
To use the Sub...

If This <> That then LockForm(True) Else LockForm(False)

Private Sub LockForm(ByVal Mode As Boolean)
On Error GoTo errTrap
Dim ctrl As Control
For Each ctrl In Me.Controls
If ctrl.Tag = "*" Then ctrl.Locked = Mode
Next
If Mode = True then Me.Caption = "Data is Read Only"
Exit Sub
errTrap:
MsgBox Err.Number & " " & Err.Description
End Sub

B Comrie
http://www.codewidgets.com
 
Thank you John,
Simple and effective.



John Vinson said:
I'd suggest setting the Form's AllowUpdates event to True or False in
its Load event, based on the identity of the author and the user.

John W. Vinson[MVP]
 
Back
Top