Locked property

S

shaggles

I am trying to set the Locked property of a comment field
based on the user id. I got the following code from vb
help in access but I get an error message saying the
object doesn't support this property or method. The field
I'm trying to lock are on a subform. Does that make a
difference? I put the code in the On Curent event of the
subform.
Private Sub Form_Current()
If Me!UserID = CurrentUser Then
Me!Response.Locked = False
Me!Sign_Off.Locked = False
Else
Me!Response.Locked = True
Me!Sign_Off.Locked = True
End If
End Sub
 
A

Allen Browne

UserID is a Text type field?
CurrentUser() is a function, so try adding the brackets.

This example sets a flag to lock the text boxes if the UserID in the form is
not the same as CurrentUser(). It also locks the fields if there is not
UserID (e.g. at a new record).

Private Sub Form_Current()
Dim bLock As Boolean
bLock = Not Nz(Me!UserID = CurrentUser(), False)
Me!Response.Locked = bLock
Me!Sign_Off.Locked = bLock
End Sub
 
S

shaggles

I keep getting the same error message no matter what I
try. UserID is a text field. Response is a memo field
and Sign_Off is a boolean field.
 
A

Allen Browne

Which line causes the error?

Is it possible that the Name of your control is not the same as the name of
the Field? If so, the field does not have a Locked property, which makes
sense of the error message.
 
S

shaggles

I was able to get this to work:
If Me!UserID = CurrentUser() Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End If
I set the locked property for Response and Sign_Off on the
Property sheet to No and on everything else to Yes. Are
there any drawbacks to doing it this way?
 
S

shaggles

Me!Response.Locked=anything or Me!Sign_Off.Locked=anything-
whichever it hits first (I tried putting Me!Sign_Off first
to make sure it wasn't the Response field only that causes
the problem.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top