Unlock a Field by fOSUserName()

I

Iram

Hello.
I need some help changing some code by one field.
I have ten fields on a form. The first five need to be edited by the person
that created the record and the other five need to be edited by a different
person. One of the ten fields is called "Created By" with a default value of
=fOSUserName()
=fOSUserName() is a module that retrieves the Windows login ID of who ever
is logged into the PC.
I have had help writing the below code (see below) however I need to alter
it to compare if the person logged into the computer is the
same as the record creator "Created By" in order to unlock each of the first
five fields. I plan on putting this code on the Double Click of each of the
first five fields...
I need the code to say something like like...
If =fOSUserName() equals to "Created By". Locked = False
If =fOSUserName() not equals to "Created By". Locked = True

Your help is greatly appreciated.
Iram/mcp




Private Sub FieldName_DblClick(Cancel As Integer)
Dim strUserName As String
strUserName = fOSUserName()

If strUserName = fOSUserName() Then
Me!FieldName.Locked = False

Else
Me!FieldName.Locked = True

End If


End Sub
 
K

Klatuu

=fOSUserName() is a module that retrieves the Windows login ID

It is not a module, it is a function. Modules are containers for subs and
functions.
And, to be a bit picky, you don't have fields on a form, they are controls.
Controls may be bound to fields.

The double click event would not be the correct event. There is nothing to
ensure a user will ever use the double click for each control, much less
ever visit the control.
If =fOSUserName() equals to "Created By". Locked = False
If =fOSUserName() not equals to "Created By". Locked = True

I would suggeset something like this in the Form Current Event.

With Me
If fOsUserName() = .CreatedBy Then
.SomeField.Locked = True
.AnotherField.Locked = True
.AnyOldField.Locked = Trhe
Else
.WheatField.Locked = False
.OutField.Locked = False
.InField.Locked = False
End If
End With
 
I

Iram

Thanks for responding.
I need the On Double Click event to deactivate the Locked controls to
prevent accidental changes to them on the form. The form has alot of List
Boxes and without the double clicking my staff can easily accidentally change
the selections.
So if I were to use the double clicking method how would I change your code?

Your help is greatly appreciated.
Iram/mcp
 

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