A family of Microsoft relational database management systems designed for ease of use.
Have you consulted Philipp Steifel's YouTube presentation and blog articles on this subject?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
A family of Microsoft relational database management systems designed for ease of use.
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.
Answer accepted by question author
Have you consulted Philipp Steifel's YouTube presentation and blog articles on this subject?
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.
What happens if you simply ignore the error with the version I posted?
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