Preventing others from making changes

I

Iram

Hello.
I am working on a database and I need a record to be shared by two types of
people, by the one who
created the record and the one who is accessing it later. There are 10 fields
in each record. The person creating the record fills in the first 5 records
and the person that accesses it later fills in the other five records. I am
using the =fOSUserName() Module and I need vba code on each of the first five
fields to say something like On Double Click...
If =fOSUserName() is not me Locked = True
If =fOSUserName() is me Locked = False

How can I write this?
Your help is greatly appreciated.

Iram/mcp
 
S

Scott Lichtenberg

You are basically there. You'll want to put the code in OnCurrent event.
This event fires off when the user moves into the record. Lock or unlock
your fields here.

Dim strUserName as String
strUserName = fOSUserName 'I'm assuming that this function
returns your user name.

If strUserName = "MyName" Then
Me!Field1.Locked = False
Me!Field2.Locked = False
Else
Me!Field1.Locked = True
Me!Feidl2.Locked = True
End If
 
I

Iram

Sorry about the wait, I was out of the office over the weekend and Thanks for
your response!
I need to use the On Double Click Event to prevent accidental changes to the
five first fields on the form so I have copied your code into the On Double
Click Event of the "Reason" field (see below modifications) however when I
double click on the field nothing happens. I have made sure that the
"Reason" field Locked is set to "No". Btw, I do have a field called "Created
By" that has the default value of =fOSUserName() if that helps any.
Can you help me figure out why nothing's happening?


Private Sub Reason_DblClick(Cancel As Integer)
Dim strUserName As String
strUserName = fOSUserName
'I'm assuming that this function returns your user name.

If strUserName = "MyName" Then
Me!Reason.Locked = False

Else
Me!Reason.Locked = True

End If


End Sub


Iram/mcp
 
I

Iram

Scott.
I need to alter your code by one field.

In my initial example I said that I needed something like this...
However since I have a field called "Created By" with a default value of
=fOSUserName()
I need your code to compare if the person logged into the computer is the
same as the record creator "Created By" in order to unlock the field.
Something like like...
If =fOSUserName() is like "Created By". Locked = False
If =fOSUserName() is not like "Created By". Locked = True

Your help is greatly appreciated.
Iram/mcp
 
I

Iram

Scott, Btw, this is working fine except for when it checks who I am logged in
as it accepts me because I am who I am or something like that.



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
 

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