Office 365 Type Mismatch (1 Viewer)

ThetaDev

New member
Local time
Yesterday, 18:24
Joined
Sep 23, 2019
Messages
3
Hello everyone. I having been updating some VBA code and now get a compile error 13 Type mismatch. This following code worked until I recompiled the module in Access 2016.

It appears that the Declared Function is not being seen by the calling Function( lenret =WinGetTempDir(BufferLen, wrkPath)). I hope this is clear. Please help. Thanks in advance.

Code:
Option Compare Database
'
' Get path of local Windows temporary folder - declaration part
'

#If Win64 Then
    Public Declare PtrSafe Function WinGetTempDir Lib "kernel32" Alias "GetTempPathA" (ByVal Buflen As LongPtr, ByVal TempPath As String) As LongLong
#Else
    Private Declare Function WinGetTempDir Lib "kernel32" Alias "GetTempPathA" (ByVal BufLen As Long, ByVal TempPath As String) As Long
#End If
---------------------------------
Public Function GetWinTempDir() As String
'
' Get path of local Windows temporary folder - return path as a string
'
    Dim wrkPath As String
    Dim lenret As Long
    Dim BufferLen As Long
    
    wrkPath = String$(255, 0)   ' Fill with nulls
    BufferLen = 255
    
    lenret = [COLOR="Red"]WinGetTempDir(BufferLen, wrkPath)[/COLOR]
    If lenret = 0 Then
        GetWinTempDir = ""
    Else
        GetWinTempDir = Left$(wrkPath, lenret)
    End If
    
End Function
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:24
Joined
May 7, 2009
Messages
19,229
you can simply use

environ("temp")

to get the temp/tmp folder
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:24
Joined
May 7, 2009
Messages
19,229
actually this is wrong:
Code:
#If Win64 Then
    Public Declare PtrSafe Function WinGetTempDir Lib "kernel32" Alias "GetTempPathA" (ByVal Buflen As LongPtr, ByVal TempPath As String) As LongLong
should be:
Code:
#If VBA7 Then
    Public Declare PtrSafe Function WinGetTempDir Lib "kernel32" Alias "GetTempPathA" (ByVal Buflen As [COLOR="Blue"]Long[/COLOR], ByVal TempPath As String) As [COLOR="blue"]Long[/COLOR]
 

isladogs

MVP / VIP
Local time
Today, 00:24
Joined
Jan 14, 2017
Messages
18,209
I'm not convinced that your API declaration is correct but can't check that till I'm on another workstation later.

However there is a much simpler method that needs no API so works in both bitnesses. Just use
Code:
Environ("temp")

EDIT I hadn't seen arnel's earlier replies when I responded
 

ThetaDev

New member
Local time
Yesterday, 18:24
Joined
Sep 23, 2019
Messages
3
Yes That worked! I had seen there were other ways to get the Temp folder location but was trying to correct code but was confused as to why it would not work with Access 2016. Anyhow I can move forward.

Thanks so much!
 

Users who are viewing this thread

Top Bottom