Complie error: Type mismatch (converting 32bit to 64bit coding) (1 Viewer)

FrozenMana

Registered User.
Local time
Today, 18:43
Joined
Aug 10, 2015
Messages
27
I have a database that was created to be used with 32-bit system of MS Access.
However the user who currently needs to utlitize this database has the 64-bit version of Office including Access. The user has been having many issues since this upgrade occured.

I added the PtrSate between Declare and Function as well as chaning Long to LongPtr. However I am now getting a complie error stating a type mismatch. My apologizes if this issue is obvious as I am still learning vba.

Code:
Option Compare Database

Private Type BROWSEINFO
  hOwner As LongPtr
  pidlRoot As LongPtr
  pszDisplayName As String
  lpszTitle As String
  ulFlags As Long
  lpfn As LongPtr
  lParam As LongPtr
  iImage As Long
End Type

Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias _
            "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As LongPtr
            
Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias _
            "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongPtr
            
Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
  Dim X As Long, bi As BROWSEINFO, dwIList As Long
  Dim szPath As String, wPos As Integer
  
    With bi
        .hOwner = hWndAccessApp
        .lpszTitle = szDialogTitle
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With
    
    dwIList = SHBrowseForFolder(bi)
    szPath = Space$(512)
    X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
    
    If X Then
        wPos = InStr(szPath, Chr(0))
        BrowseFolder = Left$(szPath, wPos - 1)
    Else
        BrowseFolder = vbNullString
    End If
End Function
Private Sub btnBrowseForFolder_Click()
    Me.txtFolderString = BrowseFolder("Hello, " & UCase(Left(WindowsLogOn, 1)) & "  " & UCase(Mid(WindowsLogOn, 2, 1)) & Right(WindowsLogOn, Len(WindowsLogOn) - 2) & ".  Please Choose the folder where your excel files are located")
End Sub
Private Sub cmdGO_Click()
    
    Call importFiles
    Call exportFiles
    Me.txtFolderString = ""
End Sub



Error message highlights and adds arrow to the yellow and also highlights in blue the blue font:
Code:
[COLOR="Yellow"][B][U]-> Public Function BrowseFolder(szDialogTitle As String) As String[/U][/B][/COLOR]
  Dim X As Long, bi As BROWSEINFO, dwIList As Long
  Dim szPath As String, wPos As Integer
  
    With bi
        .hOwner = hWndAccessApp
        .lpszTitle = szDialogTitle
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With
    
    dwIList = [COLOR="RoyalBlue"][B][U]SHBrowseForFolder[/U][/B][/COLOR](bi)
    szPath = Space$(512)
    X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
    
    If X Then
        wPos = InStr(szPath, Chr(0))
        BrowseFolder = Left$(szPath, wPos - 1)
    Else
        BrowseFolder = vbNullString
    End If
End Function

Any help is much appriciated, thank you in advance.
 
Last edited:

spikepl

Eledittingent Beliped
Local time
Tomorrow, 00:43
Joined
Nov 3, 2010
Messages
6,142
PTRsafe is not enough for a number of functions. I have a thread started by me here in this specific forum which in one of the last posts gives a link to a 64-bit copy of all the API functions. google my name and 64 and api
 

FrozenMana

Registered User.
Local time
Today, 18:43
Joined
Aug 10, 2015
Messages
27
I am on a work computer using 2013, I am unable to download an exe file to view the suggestions.

I have been looking on google as well and have found anything in reference to the area that I am getting the complie error message.

I was actually looking at the Declaring API site earlier however the edits did not fix my issue just changed the spot of the blue highlight
Changing the coding to add Ptr to Long just moves the blue highlight to a different spot:
Code:
[B][COLOR="Yellow"]-> Public Function BrowseFolder(szDialogTitle As String) As String[/COLOR][/B]
  Dim X As LongPtr, bi As BROWSEINFO, dwIList As LongPtr
  Dim szPath As String, wPos As Integer
  
    With bi
        .hOwner = hWndAccessApp
        .lpszTitle = szDialogTitle
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With
    
    dwIList = SHBrowseForFolder(bi)
    szPath = Space$(512)
    X = SHGetPathFromIDList(ByVal [B][COLOR="RoyalBlue"]dwIList[/COLOR][/B], ByVal szPath)
    
    If X Then
        wPos = InStr(szPath, Chr(0))
        BrowseFolder = Left$(szPath, wPos - 1)
    Else
        BrowseFolder = vbNullString
    End If
End Function
 
Last edited:

FrozenMana

Registered User.
Local time
Today, 18:43
Joined
Aug 10, 2015
Messages
27
Updated code that works:

Code:
Option Compare Database

'Private Type BROWSEINFO
 ' hOwner As LongPtr
  'pidlRoot As LongPtr
  'pszDisplayName As String
 'lpszTitle As String
  'ulFlags As Long
  'lpfn As LongPtr
  'lParam As LongPtr
  'iImage As Long'
'End Type '

'Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias _
            "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As LongPtr'
            
            
'Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias _
            "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongPtr '
            
Private Type BROWSEINFO
        hOwner As LongPtr
        pidlRoot As LongPtr
        pszDisplayName As String
        lpszTitle As String
        ulFlags As Long
        lpfn As LongPtr
        lParam As LongPtr
        iImage As Long
    End Type
                        
    Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" _
        (lpBrowseInfo As BROWSEINFO) As LongPtr
        
    Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
        (ByVal pidl As LongPtr, ByVal pszPath As String) As Boolean

            
Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
  Dim X As Long, dwIList As LongPtr
  Dim bi As BROWSEINFO
  Dim szPath As String, wPos As Integer
  
    With bi
        .hOwner = hWndAccessApp
        .lpszTitle = szDialogTitle
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With
    
    dwIList = SHBrowseForFolder(bi)
    szPath = Space$(512)
    X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
    
    If X Then
        wPos = InStr(szPath, Chr(0))
        BrowseFolder = Left$(szPath, wPos - 1)
    Else
        BrowseFolder = vbNullString
    End If
End Function
Private Sub btnBrowseForFolder_Click()
    Me.txtFolderString = BrowseFolder("Hello, " & UCase(Left(WindowsLogOn, 1)) & "  " & UCase(Mid(WindowsLogOn, 2, 1)) & Right(WindowsLogOn, Len(WindowsLogOn) - 2) & ".  Please Choose the folder where your excel files are located")
End Sub
Private Sub cmdGO_Click()
    
    Call importFiles
    Call exportFiles
    Me.txtFolderString = ""
End Sub
 
Last edited:

Users who are viewing this thread

Top Bottom