Solved Sleep function Not Working - error 53 kernal32 not found. (1 Viewer)

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 05:15
Joined
Apr 1, 2019
Messages
731
Hi,

I wish to introduce a 'sleep' routine into one of my forms as follows. When I run the sleepsec function I get the abovementioned error. I've done some googling and it appears that ' kernel32' is not installed. I ran chkdsk in the hope of refreshing all drivers, but still get same error message. I'm running Access64bit on 64bit Windows360. Any Clues?

Code:
Option Compare Database
Option Explicit
#If VBA7 Then
    Public Declare PtrSafe Sub sleep Lib "kernal32" (ByVal dwmilliseconds As Long)
#Else
    Public Declare Sub sleep Lib "kernal32" (ByVal dwmilliseconds As long)
#End If


Public Function sleepsec(numSec As Integer) ' convert milliseconds to seconds


   Dim x As Integer
    For x = 1 To numSec
        sleep 1000
    Next
End Function
 

561414

Active member
Local time
Today, 11:15
Joined
May 28, 2021
Messages
280
Hi,

I wish to introduce a 'sleep' routine into one of my forms as follows. When I run the sleepsec function I get the abovementioned error. I've done some googling and it appears that ' kernel32' is not installed. I ran chkdsk in the hope of refreshing all drivers, but still get same error message. I'm running Access64bit on 64bit Windows360. Any Clues?

Code:
Option Compare Database
Option Explicit
#If VBA7 Then
    Public Declare PtrSafe Sub sleep Lib "kernal32" (ByVal dwmilliseconds As Long)
#Else
    Public Declare Sub sleep Lib "kernal32" (ByVal dwmilliseconds As long)
#End If


Public Function sleepsec(numSec As Integer) ' convert milliseconds to seconds


   Dim x As Integer
    For x = 1 To numSec
        sleep 1000
    Next
End Function
If you change it to kernel32.dll, does it work?
 

isladogs

MVP / VIP
Local time
Today, 17:15
Joined
Jan 14, 2017
Messages
18,227
Spelling error: It should be Kernel32

Code:
#If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "Kernel32" (ByVal lngMilliSeconds As Long)
#Else
    Public Declare Sub Sleep Lib "Kernel32" (ByVal lngMilliSeconds As Long)
#End If
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 17:15
Joined
Sep 12, 2006
Messages
15,657
but will 64 bit access run functions in the 32 bit dll, even with the ptrsafe declaration
it may do. I'm just asking?
 

isladogs

MVP / VIP
Local time
Today, 17:15
Joined
Jan 14, 2017
Messages
18,227
Yes it will.

For info, the conditional compilation works as follows
Access versions from A2010 onwards (both 32-bit and 64-bit) use the #If VBA7 section.
Version 2007 & earlier do not have VBA7 so use the #Else section.

That applies to all API declarations, not just this one.
If all users have A2010 or later, there is no need for conditional compilation. Just use the PtrSafe version.

VBA7 interprets any instances of LongPtr as LongLong for 64-bit and Long for 32-bit
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 05:15
Joined
Apr 1, 2019
Messages
731
Friends, i'm embarrassed!. Unsuccessfully played with this routine for hours. My code compiled though so i thought the code was correct. Will make the change and try again. Cheers.
 

isladogs

MVP / VIP
Local time
Today, 17:15
Joined
Jan 14, 2017
Messages
18,227
Friends, i'm embarrassed!. Unsuccessfully played with this routine for hours. My code compiled though so i thought the code was correct. Will make the change and try again. Cheers.
Yes it would compile despite the typo.
Consider yourself demoted from Kernal to Lootenant! :D
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 05:15
Joined
Apr 1, 2019
Messages
731
All, i now get a different error message "453 Cannot find DLL entry point sleep in Kernel32.dll". Did some googling (again) reinstalled office 365, checked for windows updates (all current), ran chkdsk /r "which reported no problems found''. Then tried running same routine on another PC (32bit Access instead of 64Bit) and got same error message! I thought my 64bit access PC may have been corrupted somehow, but it didn't run on the other unrelated pc either? I'm a bit stuck for what to do next. Any ideas?
 

561414

Active member
Local time
Today, 11:15
Joined
May 28, 2021
Messages
280
All, i now get a different error message "453 Cannot find DLL entry point sleep in Kernel32.dll". Did some googling (again) reinstalled office 365, checked for windows updates (all current), ran chkdsk /r "which reported no problems found''. Then tried running same routine on another PC (32bit Access instead of 64Bit) and got same error message! I thought my 64bit access PC may have been corrupted somehow, but it didn't run on the other unrelated pc either? I'm a bit stuck for what to do next. Any ideas?
Maybe sleep should be Sleep?
Code:
Option Compare Database
Option Explicit
#If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)
#Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As long)
#End If


Public Function sleepsec(numSec As Integer) ' convert milliseconds to seconds


   Dim x As Integer
    For x = 1 To numSec
        Sleep 1000
    Next
End Function
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 05:15
Joined
Apr 1, 2019
Messages
731
I'll try that. Thanks @56414.
 

sonic8

AWF VIP
Local time
Today, 18:15
Joined
Oct 27, 2015
Messages
998
but will 64 bit access run functions in the 32 bit dll, even with the ptrsafe declaration
No, 64bit Access is not able to execute code from a 32bit DLL.
However, this question arises from an understandable misconception. Even though the name of the DLL is Kernel32.dll, this is just a name. It says nothing about the bitness of the file. The 64bit Kernel DLL is also named Kernel32.dll. - Unless you use fully qualified paths in the declarations, Access will automatically load the DLL file that is appropriate for the bitness of its current process.
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 05:15
Joined
Apr 1, 2019
Messages
731
Gents, 'Sleep' works. I'm sufficiently humiliated!!
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 05:15
Joined
Apr 1, 2019
Messages
731
One more question if i may. I wish to disable BttnClose after one click only. In testing, if I run my code & click multiple times, I eventually get the "windows is not Responding Message", then options to close, wait etc. I don't wish to see this as it would give the user an optout. I Also tried counting 'clicks' and only running the code for the first click, but this gave same error message for multiple clicks. Appreciate it & promise no more posts on this issue!!

Code:
'------------------------------------------------------------
' BttnClose_Click
'
'------------------------------------------------------------
Private Sub BttnClose_Click()


On Error GoTo ErrorHandler:


    BttnClose.Enabled = False ' disable button to prevent re-selection
    DoCmd.Hourglass True
    Call sleepsec(30) ' pause for 30 seconds
    DoCmd.Hourglass False
    DoCmd.OpenForm "frmMain", acNormal, , , acFormAdd, acWindowNormal, "NewBeekeeper"
    DoCmd.Close acForm, "frmValidate", acSaveNo




ExitError:
    On Error Resume Next
    Exit Sub
    
ErrorHandler:
    Call DisplayErrorMessage(Err.Number, "Close Button on frmValidate")
    
        Resume ExitError
        
End Sub
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 05:15
Joined
Apr 1, 2019
Messages
731
A final post, then matter closed. I added a DoEvents after sleep (1000) in the code of post #11. All good now. Thanks to all whom contributed.
 

Users who are viewing this thread

Top Bottom