Compatibility of Code both 32 BIT & 64 BIT

Hi

I have a code below all what I want is to make it compatible BIT 64 as well , how do I change it?

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal _
   lpBuffer As String, nSize As Long) As Long

Public Function GetUser() As String

   Dim strBuffer As String
   Dim lngSize As Long, lngRetVal As Long
   
   lngSize = 199
   strBuffer = String$(200, 0)
   
   lngRetVal = GetUserName(strBuffer, lngSize)
   
   GetUser = Left$(strBuffer, lngSize - 1)

End Function


Public Function GetFullName()

    Const MESSAGETEXT = "The current user is not recorded in the Users table."
    Dim strCriteria As String
    Dim varFullName As Variant
   
    strCriteria = "LoginName = """ & GetUser & """"

    varFullName = DLookup("FullName", "Users", strCriteria)
   
    If Not IsNull(varFullName) Then
        GetFullName = varFullName
    Else
        MsgBox MESSAGETEXT, vbExclamation, "Warning"
    End If
       
End Function

Public Function AddNewUser()

    Dim strCriteria As String
    Dim strLoginName As String
    Dim strFullName As String
    Dim strSQL As String
   
    strLoginName = GetUser()
    strCriteria = "LoginName = """ & strLoginName & """"
   
    If IsNull(DLookup("LoginName", "Users", strCriteria)) Then
        strFullName = InputBox("Enter new user's full name:")
        strSQL = "INSERT INTO Users(LoginName,FullName) " & _
            "VALUES(""" & strLoginName & """,""" & strFullName & """)"
   
        CurrentDb.Execute strSQL, dbFailOnError
    End If

End Function
' module ends

Regards

Chris
LVL 2
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
User Conditional Compilation:

#IF Win64 THEN
  Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal _
   lpBuffer As String, nSize As Long) As LongPtr
#Else
  Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal _
   lpBuffer As String, nSize As Long) As Long
#End If
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Couple things:

1. Most calls will need PtrSafe added.
2. Some calls are different for 32 vs 64 bit and you'll need to use compiler directives so only one executes.

 That is all discussed here:

https://www.experts-exchange.com/questions/27190589/GetUserName-fails-on-64bit-Access.html

 along with some good links:

https://www.experts-exchange.com/questions/27190589/GetUserName-fails-on-64bit-Access.html#a36167741

 on all the calls you need and a code inspector to tell you what needs to be changed.

Jim.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
BTW, in direct reference to your question, from that other thread:

https://www.experts-exchange.com/questions/27190589/GetUserName-fails-on-64bit-Access.html#a41843528

Jim.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.