VBA Compile error when using #IF Win64 then Public Declare Sub Sleep Lib "kernel32"

Anonymous
2020-12-10T18:15:15+00:00

This has been bugging me for a while now and I have been unable to resolve this compile error.  I am running Windows 10 Enterprise 64bit.  My version of Office is Microsoft 365 Apps for Enterprise.  The issue is when I try to use the conditional directive to declare the sleep sub.  I am getting the compile error below.  I have tried using VBA7 and Win64 separately as well together as below with the same result.  I created a blank module and placed only code below to duplicate the error.

For now I am commenting out the 32 bit line, but would like to find a way to resolve this.  I appreciate any insights into this.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

6 additional answers

Sort by: Most helpful
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2020-12-10T18:32:55+00:00

    Use this instead:

    #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

    0 comments No comments
  2. Anonymous
    2020-12-10T18:48:46+00:00

    Thanks for the quick response, but I get the same result compile error.  I have tried IF VBA7, IF Win64 & If VBA7.  I thought my image of the error was uploaded.  I'll update my original post with the source & error.

    0 comments No comments
  3. HansV 462.4K Reputation points MVP Volunteer Moderator
    2020-12-10T21:09:10+00:00

    What happens if you simply ignore the error with the version I posted?

    0 comments No comments
  4. Anonymous
    2020-12-10T21:36:07+00:00

    I created a blank DB and new module with the code below.  Even though I get the compile error when I paste or edit the directives, it will run the sub TestSleep without issue.  The only thing I see is the 32bit line is colored in red.  I don't have a 32 bit version to test with currently, but I suspect it will work as well.

    Option Compare Database

    Option Explicit

    #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

    Sub TestSleep()

        Debug.Print "Before Sleep"

        Sleep 100

        Debug.Print "After Sleep"

    End Sub

    I'll watch the video you linked shortly.

    0 comments No comments