I am very new to code, and need to make a form uneditable to users
who
are not the author of the record, as well as make uneditable to anyone
once a "completed" button is pushed which sets the date into a table.
Any help would be greatly appreciated.
Do you have a function which identifies the current user? Do you store this
as part of the record when records are created? If so, then you use the
forms Current event which runs as you arrive at each record.
(all field names and functions are EXAMPLES)
If Me!CompletedField = True _
Or Me!CreatedByField <> CurrentUserFunction() Then
'code to lock record
Else
'code to unlock record
End If
Now, what about that locking/unlocking code? The easiest is just to use
AllowEdits...
If Me!CompletedField = True _
Or Me!CreatedByField <> CurrentUserFunction() Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If
One downside of this is that it locks everything on the form, not just the
data-bound controls. If you had for example an unbound ComboBox used for
navigating then it would also be locked and not usable. If you have no such
controls then AllowEdits is the way to go.
If AllowEdits is a problem, then I would loop through all the controls and
lock the desired ones. I usually identify these by giving them all a common
Tag property entry...
If Me!CompletedField = True _
Or Me!CreatedByField <> CurrentUserFunction() Then
RecordLock(True)
Else
RecordLock(False)
End If
Function RecordLock(LockUnlock as Boolean)
Dim cnt as Control
For Each cnt in Me
If cnt.Tag = "MyTagString" Then cnt.Locked = LockUnlock
Next cnt
End Function