pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
jo*******@hotmail.com (Joe) wrote in message news:<74**************************@posting.google. com>... Hi there, question regarding Access 2000 - locking records:
I want to be able to lock a record (or several records) on a form so
that particular record can not be edited until I undo the lock (im the
administrator and have a password). I want to be able to lock the
record on the form by pressing a button. Once the button is pressed a
flag appears which displays that particular record as locked. Can
anyone help with this?
Thanks, Joe
One way - add a yes/no field to the underlying table, something like
"LockRecord".
Put this field on your form, but not visible (should show as a
checkbox). Then in the OnCurrent event of your form, do something like
Me.AllowEdits=me.chkLockRecord
which will toggle the lock On/Off.
The "admin" form will not have this yes/no field locked so it can be
edited.
That's a good idea, Pieter. I have a further suggestion. Instead of
creating two separate forms, you can put this code in a module...
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function GetUserName() As String
' Returns the network login name
' From: Dev Ashish
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
GetUserName = Left$(strUserName, lngLen - 1)
Else
GetUserName = ""
End If
End Function
so that you can unlock and unhide the LockRecord checkbox when the
'Administrator' opens the form. That seems easier than having to
maintain an extra form. However, this function can take a second or
more to run so a separate form might be better if the form needs to
open quickly.
James A. Fortune