Learning is not attained by chance, it must
be sought for with ardor and diligence.
-Abigail Adams
 
Home   News   Courses   Seminars   Templates   Help   TechHelp   Forums   Order   Contact   Logon  
 
Home > Code Vault > Generic VBA > SleepSec
 
Sleep Seconds
By Richard Rost   Richard Rost on Facebook Richard Rost on Twitter Richard Rost on LinkedIn Email Richard Rost   3 months ago

This procedure will determine how long Alex naps for.

#If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)
#Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long)
#End If

Public Sub SleepSec(NumSec As Long, Optional AllowEvents As Boolean = True)
    Dim X As Integer
    For X = 1 To NumSec
        Sleep 1000
        DoEvents
    Next
End Sub

Usage:

Put the above in a global module, then anywhere in your database you can say something like this to sleep for 5 seconds:

SleepSec(5)

The purpose of the loop is to make SleepSec responsive. If you sleep for 10 seconds without any DoEvents, then your code might appear to freeze. If this interferes with performance or function for you, just set it to FALSE.

 

Post a New Comment or Question
 
Only students may post right now. Click here for more information on how you can set up an account. If you are a student, please LOG ON first.
 
Subscribe
 
 
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search The Site
Waiting List
Production Schedule
Code Vault
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

YouTube Channel    LinkedIn

Blog RSS Feed   
Keywords: code vault generic vba sleepsec sleep seconds  PermaLink