Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #11 (permalink)  
Old February 3rd, 2007, 01:28 PM
Authorized User
 
Join Date: Nov 2006
Location: Bedfordshire, , United Kingdom.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Everyone,
Can anyone help me to pause a vb program for about 2 minutes.
I have used the Sleep method but want to see if there is a better one.

Thank You
Ash

arshad Mehmood
Reply With Quote
  #12 (permalink)  
Old April 3rd, 2007, 02:56 PM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

a not very graceful, but easy alternative:

Dim nw As Date
Dim i as integer
nw = DateAdd("s", 3, Now())
While DateDiff("s", Now(), nw) > 1
     i= i 'i.e. wait three seconds
Wend
Reply With Quote
  #13 (permalink)  
Old June 14th, 2007, 12:52 AM
Registered User
 
Join Date: Jun 2007
Location: , , Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi, mate,

Why not just try "For loop structure", something like
For j = 1 To 10000000

Next j

it can be last for a while.
hope it can be helpful

Reply With Quote
  #14 (permalink)  
Old February 13th, 2010, 10:42 AM
Registered User
 
Join Date: Feb 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Wait Function

Quote:
Originally Posted by MrInterface View Post
I use the following function:

Public Function fnWait(intNrOfSeconds As Integer)
Dim varStart As Variant
  varStart = Timer
  Do While Timer < varStart + intNrOfSeconds
  Loop
End Function
This works perfectly, when you are accessing a database via VBA on Excel and then you want to perform some calcutions in VBA right after the table is returned.

So to the author of the script, thank you very much.
FHanFreeman
13-Feb-2010.
Reply With Quote
  #15 (permalink)  
Old December 18th, 2010, 11:43 AM
Registered User
 
Join Date: Dec 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's worth mentioning that looping with DoEvents in the middle is going to tie up your CPU, using the API method will not.

Code:
Private Declare Sub APISleep Lib "kernel32" Alias "Sleep" (ByVal lngMilliseconds As Long)

Public Function Sleep(lngSeconds As Long) As Boolean
  If lngSeconds > 0 Then
    Call APISleep(lngSeconds * 1000)

    Sleep = True
  End If

End Function
Reply With Quote
  #16 (permalink)  
Old December 18th, 2010, 04:16 PM
Friend of Wrox
Points: 952, Level: 12
Points: 952, Level: 12 Points: 952, Level: 12 Points: 952, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Posts: 227
Thanks: 5
Thanked 24 Times in 23 Posts
Default

Quote:
Originally Posted by heroadu View Post
hi, mate,

Why not just try "For loop structure", something like
For j = 1 To 10000000

Next j

it can be last for a while.
hope it can be helpful
The problem with this approach is that it will not give you constant results for the amount of delay.

Back in the days of the first PC's ( old XT's) your method was a common practice. Then the 286 machines cam out. The processor were so much faster that the loops like you suggest we being performed very fast. Games were executing so fast the human could not keep up. You have to run a special program to script the processor to slow it down enough that a humans could keep up. Games had to be rewritten to pause based in the passing of time. Once this method was used games were still be playable on the newer and faster CPUs.
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft MVP - Access Expert
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA function help carbon_13 Excel VBA 2 March 5th, 2008 04:17 PM
Wait In VB ashes0000 Beginning VB 6 5 February 6th, 2007 10:47 AM
Should I wait for .net 2 androoo ADO.NET 2 November 3rd, 2004 08:07 AM
help me! wait online EdmondWang All Other Wrox Books 1 December 18th, 2003 05:16 AM



All times are GMT -4. The time now is 03:05 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.