Results 1 to 7 of 7
  1. #1
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    122

    how to get user id in access query

    I wonder how to get user id in access query I am using in field. I am pulling some info but I want to add field who pulled this info as username



    User: Environ ( "UserName") but not working.


    I have another question how to generate serial number in access query when we pull data. I mean can it show row number 1,2,3,4.................

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    There are no row numbers in Access. If you want to put some record sequence on the results of a query or recordset, you could do that.

    For your user issue

    Create a function as below
    Code:
    Function getuser() As String
     getuser = Environ("username")
    End Function
    Then in your query use (best guess)

    SELECT getuser() AS [User] FROM yourtableNameGoesHere; or in the query wizard User: GetUser()

  3. #3
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    122
    Quote Originally Posted by orange View Post
    There are no row numbers in Access. If you want to put some record sequence on the results of a query or recordset, you could do that.

    For your user issue

    Create a function as below
    Code:
    Function getuser() As String
     getuser = Environ("username")
    End Function
    Then in your query use (best guess)

    SELECT getuser() AS [User] FROM yourtableNameGoesHere; or in the query wizard User: GetUser()
    Thanks for reply where should I write this code. Should I create form first ? how can I add this value in my result ? Kindly explain? I am not expert in access

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Create a standard module

    copy and paste the function into the module
    when saving the module, name it anything but getUser.
    It will probably default to module1, just accept that.

    Then for your query for testing - in the SQL View, type
    SELECT getuser() AS [User] FROM yourtableNameGoesHere;

  5. #5
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    122
    Quote Originally Posted by orange View Post
    Create a standard module

    copy and paste the function into the module
    when saving the module, name it anything but getUser.
    It will probably default to module1, just accept that.

    Then for your query for testing - in the SQL View, type
    SELECT getuser() AS [User] FROM yourtableNameGoesHere;
    My module1 I just saved would be my table ? what will be table name ?

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    I think you're getting mixed up in orange's suggestion, the function he mentions is independent of the table

    SELECT [YOURTABLENAMEGOESHERE.]*, getuser() as CurrentUser
    FROM [YOURTABLENAMEGOESHERE]

    orange's example is just that, an example, you'd get the same user for every record in your source table, if you want to actually show records associated with that table you'd have to add them to your SQL statement.

  7. #7
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    122
    Quote Originally Posted by rpeare View Post
    I think you're getting mixed up in orange's suggestion, the function he mentions is independent of the table

    SELECT [YOURTABLENAMEGOESHERE.]*, getuser() as CurrentUser
    FROM [YOURTABLENAMEGOESHERE]

    orange's example is just that, an example, you'd get the same user for every record in your source table, if you want to actually show records associated with that table you'd have to add them to your SQL statement.
    oh I got it . It works. Thank you very much you and orange, you guys are awesome!

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

Similar Threads

  1. Replies: 3
    Last Post: 09-28-2016, 03:11 AM
  2. Replies: 1
    Last Post: 06-03-2016, 08:23 PM
  3. Replies: 2
    Last Post: 01-16-2015, 06:43 PM
  4. Replies: 13
    Last Post: 11-18-2013, 02:20 PM
  5. Query Question (new access user)
    By lewismk in forum Queries
    Replies: 2
    Last Post: 01-05-2011, 08:21 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