Results 1 to 11 of 11
  1. #1
    ducecoop is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    41

    Who created new record

    In Access 2003 I used to use the following in as the default value in a field called “AddedBy”
    =Environ("username")

    This does not seem to work in 2007 and 2010.



    Any alternative method for a one login situation, (All users have the same DB login) that can pull their computers login username?


    tia
    Dave
    Last edited by ducecoop; 10-28-2010 at 02:40 PM.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ducecoop is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    41
    OK - I looked at that and was not sure how to "Call it"
    I did create the madule and tried just calling it from the default vaule attribute of the "AddedBy" field

    = fOSUserName()

    got an error saying function not found.

    Did I create the function wrong
    or
    is that not the place to call it from

    Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That should work. It's in a standard module (not behind a form or report)? Make sure the module doesn't have the same name as the function, and make sure you've saved it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ducecoop is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    41
    Quote Originally Posted by pbaldy View Post
    That should work. It's in a standard module (not behind a form or report)? Make sure the module doesn't have the same name as the function, and make sure you've saved it.
    Modal is saved and with a different name then the function and is not behind a form or report

    This is the error I get:


  6. #6
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Maybe type "Public" before the Function declaration in the module?

  7. #7
    ducecoop is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    41
    Quote Originally Posted by slave138 View Post
    Maybe type "Public" before the Function declaration in the module?
    If I understood you correctly I tried that with the same error results

    here is the Modal code

    Code:
    Option Compare Database
    
    
    '******************** 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
    
    Public 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

  8. #8
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    What's the name of the module?

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Are you trying to make this the default value at the table level? I'm not sure that will work. I just tested and got the same error. It will definitely work as the default value of a textbox on a form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    ducecoop is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    41
    Quote Originally Posted by pbaldy View Post
    Are you trying to make this the default value at the table level? I'm not sure that will work. I just tested and got the same error. It will definitely work as the default value of a textbox on a form.
    Yes I was trying to use it as a default value at table level.
    I actually did not have the field on any form since the field was mostly for security and follow-up purposes.
    I added it as a hidden field to the necessary forms and as you said - works great.

    Thanks to all


    Dave

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad it worked for you.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to work with .dbf file created by GIS
    By cowboy in forum Programming
    Replies: 8
    Last Post: 09-28-2010, 10:26 AM
  2. Replies: 1
    Last Post: 09-21-2010, 09:49 AM
  3. Create a variable from a query created in VBA
    By kaelcarp in forum Programming
    Replies: 4
    Last Post: 06-11-2010, 09:13 PM
  4. User created Hyperlink
    By kaylachris in forum Forms
    Replies: 3
    Last Post: 05-17-2010, 02:40 PM
  5. New Field Name on Newly created query
    By inan25 in forum Queries
    Replies: 3
    Last Post: 05-13-2009, 09:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums