Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CurrentUser as Default value in Table

Status
Not open for further replies.

dtutton

Technical User
Mar 28, 2001
58
DE
Im hoping to avoid modules, macros etc as Im a new user.
Is there any way that in a table definition that I can put an expression in a Default value that picks up the current user i.e. something like CurrentUser() the same way as now() for current date.

Thanks
 
Hi, should have said, if you have security in place at least to the point of users having to log in to access, otherwise CurrentUser() always returns "Admin"

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thanks Ken

That is what I had been trying but I get "Unknown user 'CurrentUser' in validation expression or default value on table1" when I close the design editor of the table.

Thanks

David
 
I don't believe that you can set a default for a field like that in table design. You can create a default in a control on a form. Try display data on forms and reports only.

If you want the user's login, there is code at Create a new, blank module and paste this code into it. Save the module as "basUserName". Then set the default value of a text box to;
=fOSUserName()

Code:
'******************** Code Start **************************
' 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
'
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 = vbNullString
    End If
End Function
'******************** Code End **************************

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top