Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sleep Lib "kernel32" gives 64-bit systems error

Tags:

vba

ms-access

I'm trying to close access (Application.Quit) after running all functions.

VBA close access after all functions finished has been a reference for me.

but when I Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long), It's giving me the following error:

The code in this project must be updated for use on 64 bit systems.

Is there any replacement of this code to do run all functions before completely closing access?

like image 248
John Tipton Avatar asked Jan 13 '17 15:01

John Tipton


2 Answers

The dwMilliseconds parameter is a DWORD, so it will technically be 32bit on a 32bit machine and 64bit on a 64bit machine. Because of this, it requires PtrSafe notation (although technically dwMilliseconds will marshal correctly because it's ByVal... and who wants to wait that long anyway) Change the declaration to this:

#If VBA7 Then
    Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
like image 136
Comintern Avatar answered Oct 20 '22 21:10

Comintern


change your api declaration to this :

#If VBA7 And Win64 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If

For 64bit APIs read this: http://www.jkp-ads.com/articles/apideclarations.asp

like image 5
cyboashu Avatar answered Oct 20 '22 21:10

cyboashu