Results 1 to 4 of 4
  1. #1
    Jaik is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2016
    Posts
    33

    Convert fousername 32 bit code to 64 bit



    Code:
    Option Compare Database
    
    
    #If Win64 Then
    Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As LongPtr) As Long
    #Else
        Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    #End If
    
    
    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
    Hi guys, I am trying to modify code to work both in 32 bit and 64 bit. However, the code gives me the "ByRef argument type mismatch" error.
    Is there any way to resolve this error?

    Thank you!

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I've used it this way without compile errors
    Code:
    #If VBA7 Then
    Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
        "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    #Else
    Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
        "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    #End If
    Not that I think using VB7 instead of W64 is the key (because I don't know) but I think it's your use of LongPtr. Try both.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Jaik is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2016
    Posts
    33
    Thank you so much! it works fine now.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    So which was it?

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

Similar Threads

  1. Replies: 3
    Last Post: 01-26-2016, 01:56 PM
  2. to convert SQL to VBA!!!!!!!!!!!
    By mathhero in forum Access
    Replies: 1
    Last Post: 10-30-2015, 07:34 AM
  3. convert to mde
    By linoreale in forum Access
    Replies: 5
    Last Post: 05-14-2015, 09:09 AM
  4. Convert to DD:HH:MM:SS
    By denknee in forum Programming
    Replies: 2
    Last Post: 10-06-2014, 04:55 PM
  5. Convert Access 07 ADO code to SQL Server Express 2008
    By jrdnoland in forum Programming
    Replies: 8
    Last Post: 04-14-2010, 05:57 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