Current User function

  • Thread starter Thread starter Jdougal via AccessMonster.com
  • Start date Start date
J

Jdougal via AccessMonster.com

I know to "grab" the name of the current user you use the currentuser()
function. I am attempting to create a field named "name" where this
information will be stored each time the form is filled out. How exactly
would I go about implementing this function?

I am relatively new to Access so please take that into consideration, and
have no VB background.

Thanks
 
Firstly, don't use a field called Name. Forms and most other things have a
Name property, and Access will get confused what you are referring to. For
this example, we will call the field UpdatedBy.

1. Open the form in design view.

2. Open the Properties box (View menu.
Its title bar must read "Form", indicating you are looking at the properties
of the form, not those of a text box.

3. On the Event tab, set the BeforeUpdate property to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

4. Enter this line between the 2 Access gives you:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.[UpdatedBy] = CurrentUser()
End Sub
 
Thanks a lot!

How would I display this information on that same form? Basically to show the
person that they are logged into their name?

Allen said:
Firstly, don't use a field called Name. Forms and most other things have a
Name property, and Access will get confused what you are referring to. For
this example, we will call the field UpdatedBy.

1. Open the form in design view.

2. Open the Properties box (View menu.
Its title bar must read "Form", indicating you are looking at the properties
of the form, not those of a text box.

3. On the Event tab, set the BeforeUpdate property to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

4. Enter this line between the 2 Access gives you:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.[UpdatedBy] = CurrentUser()
End Sub
I know to "grab" the name of the current user you use the currentuser()
function. I am attempting to create a field named "name" where this
[quoted text clipped - 3 lines]
I am relatively new to Access so please take that into consideration, and
have no VB background.
 
Pardon me,

I might point out that unless you have set up Access security on your
database
CurrentUser() is going to return "Admin" every time.

If you want the user's network login or windows login that will use
different code.

Use the code at the following URL to get the current OS user name.
http://www.mvps.org/access/api/api0008.htm

Allen Browne said:
Firstly, don't use a field called Name. Forms and most other things have a
Name property, and Access will get confused what you are referring to. For
this example, we will call the field UpdatedBy.

1. Open the form in design view.

2. Open the Properties box (View menu.
Its title bar must read "Form", indicating you are looking at the
properties of the form, not those of a text box.

3. On the Event tab, set the BeforeUpdate property to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.

4. Enter this line between the 2 Access gives you:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.[UpdatedBy] = CurrentUser()
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jdougal via AccessMonster.com said:
I know to "grab" the name of the current user you use the currentuser()
function. I am attempting to create a field named "name" where this
information will be stored each time the form is filled out. How exactly
would I go about implementing this function?

I am relatively new to Access so please take that into consideration, and
have no VB background.
 
Just put this into the Control Source property of a text box:
=CurrentUser()

BTW, make sure you read John Spencer's reply as well, in case you don't have
Access security set up.
 
Sorry I didn't mention it, I have set up multi-users within Access.

John said:
Pardon me,

I might point out that unless you have set up Access security on your
database
CurrentUser() is going to return "Admin" every time.

If you want the user's network login or windows login that will use
different code.

Use the code at the following URL to get the current OS user name.
http://www.mvps.org/access/api/api0008.htm
Firstly, don't use a field called Name. Forms and most other things have a
Name property, and Access will get confused what you are referring to. For
[quoted text clipped - 23 lines]
 
Back
Top