By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

locking records on a form

P: n/a
Joe
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
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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


Nothing doing. Add a field to your underlying table. Something like
"AllowEditing" as a yes/no field. Then put the field on your form(s)
- for YOUR form, it will always be visible/enabled. On the form you
give others, it won't be visible/editable.

Then put code like this in the Current event of the form...

Private Sub Form_Current()
Me.AllowEdits = Not Me.chkRecordLocked
End Sub

(chkRecordLocked is the flag in my table.) Of course, you'll have to
view a single record at a time, though...
Nov 13 '05 #2

P: n/a
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.
Nov 13 '05 #3

P: n/a
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
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.