=CurrentUser

sefa333

Registered User.
Local time
Yesterday, 16:09
Joined
Nov 17, 2011
Messages
19
is there a way to get current user in a table by adding something like =currentuser to default field?
 
not sure

try putting that as the default value for a field

if it doesn;t like it, then in the form's beforeupdate event just put this, which will initiallise the value for new records.


if me.newrecord then userfield = currentuser()

However, note that if you aren't using access security, this will always give you "Admin"

Instead you can get the windows username by

if me.newrecord then userfield = environ("username")
(maybe its environ("user name") with a space)
 
thanks for your input. will try this to see if it works
 
By the way, which user are you talking about? The current machine/network user or the current db user? If you have permissions and groups set in your db are you referring to the current db user?
 
Thanks. I am very new to Access. Here is in more detail what i am trying to do. A person will update a record by opening a form of that record. After the info is changed, there is a command button that will run an append Query to move the update to a new table. My boss wants to record all changes to this info on a separate table. He want the current date/time (=Now ()) and current log in from window. I don’t know VB code or how to build Modules. Sorry have not got that far yet. Let me know if you can help. Thanks again
 
I'm sorry i dont understand function name in the Default Value property. what funtions name? and are you talking about the Default Value Property in the table. If so what am i putting there (i.e. =Currentuser or something of sort.) sorry very new to Access. thanks
 
yes i got the link. trying to figure out what to do and how to do it.
 
1. Create a new MODULE and paste this in:
Code:
Option Compare Database
              

' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of Dev Ashish at The Access Web


Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
    Dim lngLen As Long, lngX As Long
    Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If lngX <> 0 Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = ""
    End If
End Function
2. Save the name of the module as modUserName
3. Put=fOSUserName() in the Default Value property of the field or textbox.
 
ok. it worked in a text box, when i put in the Default Value in my table is gives me an error message-- unknow function 'FOSUserName' in validation expression or default value on 'Table1.empname'. Sorry I am on a network. the text box show my #. is it possible to convert that to name. thanks for all your help and patience.
 
Then it has to be used in a form.

It is returning exactly what your username is. Your Network Administrator is using IDs.
 
ok. thanks. i also ran it in a query and it worked. thanks for all your help.
 
Sorry. one more thing. i am using a copy on a database(that is not split) to get all of this to work. when i go to put this into the functioning database that is already split (front end and back end), which end do i put the module in or does it matter.
 
The BE of your split db will only contain tables. Which part do you think it would be (forced to) go in? ;)
 
the append query will send it to the table. so the back end i would assume.
 
I just mentioned that the Back End will ONLY contain tables and NOTHING ELSE.

Your Front End will contain everything else. What does this mean?
 
the front end is where everything happens. the back end is only where we store data to be retrieved so it need to go in the front end. thanks for helping me to understand what to do and why to do it. this is the first project i have worked on for a company. i will have a lot of question. could you recommend a good starter book on Access for me.
 

Users who are viewing this thread

Back
Top Bottom