none
64 bit Office to open 32 bit Database RRS feed

  • Question

  • My company is upgrading folks randomly to the 64 bit version of Office (Microsoft Access).  My company is huge, and the IT department will do as they please.  My problem is that none of our 32 bit databases will work on the 64 bit versions of Office. 

    The code that is causing the issue has been pasted below, and is present in all four of the database I am having issues with.

    Any suggestions on how to make this work for both 32 and 64 bit versions of office?

    Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
        "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Function fOSUserName() As String
    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

    Tuesday, September 27, 2016 4:55 PM

Answers

All replies

  • See: http://www.access-programmers.co.uk/forums/showthread.php?t=201306 for a 64 bit version.  You should probably read: http://www.utteraccess.com/forum/office-2010-x64-bit-qu-t1914261.html to get a better understanding

    Also, since it sounds like you'll be dealing with people on both 32 and 64 bot at the same time, you'll probably need to add conditional compiling to your API.

    http://www.utteraccess.com/wiki/index.php/Conditional_Compilation

    Don't forget to compile one version on a 32 bit version of Access for your 32 bit users, and compile a separate version on a 64 bit Access installation for your 64 bit users.


    Daniel Pineault, 2010-2015 Microsoft MVP Professional Support: http://www.cardaconsultants.com MS Access Tips and Code Samples: http://www.devhut.net


    Tuesday, September 27, 2016 5:01 PM
  • Daniel Pineault resolved my issue with a link. For those of you that don't like to follow external links, this is what I used (see below). This code replaced mine (I did not do a conditional statement).

    Option Compare Database
    Option Explicit
    
    'OLD:- Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As LongPtr) As Long
    '-----------------------------------------------------------------------------------------
    ' This code is used to retrieve the network user name by accessing the API apiGetUserName.
    ' Created by: Unknown (Found on Dev Ashish web site http://home.att.net/~dashish/api)
    ' This code has not been altered in anyway.
    ' Added to database: 27 Dec 1999
    ' Added by: Richard Rensel
    '-----------------------------------------------------------------------------------------
    
    Function fOSUserName() As String
    On Error GoTo fOSUserName_Err
    
        Dim lngLen As LongPtr, lngX As LongPtr
        Dim strUserName As String
        
        strUserName = String$(254, 0)
        lngLen = 255
        lngX = apiGetUserName(strUserName, CInt(lngLen))
            
        If lngX <> 0 Then
            fOSUserName = Left$(strUserName, CInt(lngLen) - 1)
        Else
            fOSUserName = ""
        End If
        
      
    fOSUserName_Exit:
      Exit Function
      
    fOSUserName_Err:
      MsgBox Error$
      Resume fOSUserName_Exit
    End Function

    Tuesday, September 27, 2016 6:55 PM
  • I should have said, this code allowed me to open using 32 bit and 64 bit versions of office at the same time.
    Tuesday, September 27, 2016 6:56 PM