Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2007, 02:28 PM
Authorized User
 
Join Date: Nov 2006
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
 
Old April 3rd, 2007, 02:56 PM
Registered User
 
Join Date: Apr 2007
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
 
Old June 14th, 2007, 12:52 AM
Registered User
 
Join Date: Jun 2007
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

 
Old February 13th, 2010, 11: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.
 
Old December 18th, 2010, 12:43 PM
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
 
Old December 18th, 2010, 05:16 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
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 Access MVP Alumni 2010-2015





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.