capture username who created a record

G

Guest

I have a form where there are many users to enter or update data. I need to
capture the username who created a record , then , on form load , I want
system to check for username if it is same as the creator of a record , then
allow update , otherwise don’t allow update , but allow only adding new
records. How can I do this
 
K

Keith W

mhmaid said:
I have a form where there are many users to enter or update data. I need to
capture the username who created a record , then , on form load , I want
system to check for username if it is same as the creator of a record ,
then
allow update , otherwise don't allow update , but allow only adding new
records. How can I do this

To capture the network user ID I use the "Environ" property (you can look it
up in the help). To compare the network ID with a stored ID you'd need
something like this in the form's Current event:

If Me.txtMyTextBox = Environ("USERNAME") Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End If

You'd have to code to allow for adding/deleting records too.

HTH - Keith.
www.keithwilby.com
 
D

Douglas J Steele

Keith W said:
To capture the network user ID I use the "Environ" property (you can look it
up in the help). To compare the network ID with a stored ID you'd need
something like this in the form's Current event:

If Me.txtMyTextBox = Environ("USERNAME") Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End If

I always cringe when people suggest using Environ to track user ids, since
it's trivial to reset an environment variable.

Far better is to use the API call illustrated in
http://www.mvps.org/access/api/api0008.htm at "The Access Web"
 
K

Keith W

Douglas J Steele said:
I always cringe when people suggest using Environ to track user ids, since
it's trivial to reset an environment variable.

Hi Doug, could you expand on this please? I'm not sure I understand what
you mean by "trivial to reset an environment variable".

Thanks.
Keith.
 
D

Douglas J Steele

Keith W said:
Hi Doug, could you expand on this please? I'm not sure I understand what
you mean by "trivial to reset an environment variable".

Open a DOS box and type:

SET USERNAME

Next, type

SET USERNAME=xxxx

Type SET USERNAME again.

Granted, in this case it's only going to be valid in that DOS session (i.e.
if you close the DOS box, reopen it and type SET USERNAME again, you'll get
the correct information), but you can create a batch file that sets Username
to whatever you want then open the database (using <full path to
msaccess.exe> <full path to database>)
 
K

Keith W

Douglas J Steele said:
Open a DOS box and type:

SET USERNAME

Next, type

SET USERNAME=xxxx

Type SET USERNAME again.

Granted, in this case it's only going to be valid in that DOS session
(i.e.
if you close the DOS box, reopen it and type SET USERNAME again, you'll
get
the correct information), but you can create a batch file that sets
Username
to whatever you want then open the database (using <full path to
msaccess.exe> <full path to database>)

Duly noted, thanks.
 

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