Results 1 to 4 of 4
  1. #1
    Tom1 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    13

    VBA code for retrieving username in Access 2013 64bit

    Hello,
    I have code that can retrieve the username of the current person logged onto windows in Access 2010 32bit.


    Code:
    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
    We are starting to move over to Access 2013 64bit and when we open the database up it goes into debug mode.
    Does anyone know what changes to this code need to take place in order for me to still retrieve their windows sign on name?

    Also, not all the laptops that use the database will be swapped over at once, so some will have the old 2010 32bit and some will have 2013 64bit, can code be created to find what system they're using before the code retrieve's their sign on details?

    Thank you in advance for your help!!!!!!!

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Have you tried using environ("username") to return the windows login?

  3. #3
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    You need to use the PtrSafe Attribute with any Declare statements in a 64 bit Office environment. See this kb article for more details.

  4. #4
    Tom1 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    13
    Thank you both for your replies, that PtrSafe has worked a treat. Your a star!

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

Similar Threads

  1. Replies: 14
    Last Post: 08-17-2015, 02:32 AM
  2. Cascade Combo Box - Help! Access 2013
    By alamp85 in forum Forms
    Replies: 4
    Last Post: 04-09-2013, 03:49 PM
  3. “PivotCharts” in the Access 2013
    By jamal numan in forum Access
    Replies: 6
    Last Post: 02-16-2013, 04:06 PM
  4. Replies: 2
    Last Post: 10-26-2012, 01:18 PM
  5. Replies: 1
    Last Post: 04-08-2011, 08:06 PM

Tags for this Thread

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