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
  #1 (permalink)  
Old January 24th, 2005, 12:32 PM
Authorized User
 
Join Date: Oct 2003
Location: Cleveland, OH, USA.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default "Wait" function in VBA

Hi Everyone,

Does anyone know an API or other function to run the
equivalent of the VB Wait() function using VBA?

The code runs within an MS Access module, so I can't
use the TimerInterval available with forms.

Any help would be SUPER appreciated!

Thank You,

Warren
:)
Reply With Quote
  #2 (permalink)  
Old January 24th, 2005, 01:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 10 Times in 9 Posts
Default

Far as I know, the only way to pause processing in VBA is through work-around error handling solutions. VBA doesn't give you any control over process or thread execution with methods like Thread.Sleep() or Wait(), etc, that I'm aware of. You could try something like the following. Here I'm trying to write to a file that some other process is hypothetically creating, and need to pause processing if the file doesn't exist yet:

Sub WriteToFile()

    Dim intWait As Integer

    Set oFso = CreateObject("Scripting.FileSystemObject")

    On Error Resume Next

    Set oFile = oFso.OpenTextFile("C:\SomeFile.txt", ForAppending, True)

    ' Error opening file(e.g. doesn't exist yet).
    Do While Err.Number <> 0
        ' Slow the processing down a bit before trying again
        For intWait = 1 To 100
            DoEvents
        Next
        Err.Clear
    ' Try opening file again.
    Set oFile = fso.OpenTextFile("C:\LogCalls.txt", ForAppending, True)
    Loop

    'Write to text file.........................

    oFile.Close
    Set oFile = Nothing
    Set oFso = Nothing

End Sub

Don't know if thats at all helpful, but might give you some ideas.

HTH,

Bob

Reply With Quote
  #3 (permalink)  
Old January 24th, 2005, 01:38 PM
Authorized User
 
Join Date: Oct 2003
Location: Cleveland, OH, USA.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you, Bob! :)
Reply With Quote
  #4 (permalink)  
Old January 24th, 2005, 03:01 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep(600000)

This sleeps for 10 minutes, I think. I can't remember how long 600K is. It's either 5 or 10 minutes.





mmcdonal
Reply With Quote
  #5 (permalink)  
Old January 24th, 2005, 03:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 10 Times in 9 Posts
Default

Hi mmcdinal,

Which object library is WScipt in? Can it be referenced in a VBA project, or is it just a VBScript thing? I tried referncing the Windows Script Host Object Model in VBA, but can't instantiate an instance of WScript.Shell.

- Bob

Reply With Quote
  #6 (permalink)  
Old February 3rd, 2005, 07:48 PM
Registered User
 
Join Date: Feb 2005
Location: Peoria, IL, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Something I've used as a workaround before is the wait option in a SendKeys statement. The line below will send a <Shift> and wait until the keystroke is processed before returning control to the procedure.

SendKeys "+", True

Regards,

Bonnie

Reply With Quote
  #7 (permalink)  
Old February 4th, 2005, 04:57 PM
Authorized User
 
Join Date: Oct 2003
Location: Cleveland, OH, USA.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

And I have returned with good news, everyone. Put this
into your Declarations section in either your module
or form/report source code:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Here's a sample call:

Sleep (5000) ' Waits for 5 seconds

Rescued by an API!

Thank you all for your help!
Reply With Quote
  #8 (permalink)  
Old May 30th, 2006, 12:19 PM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello everyone,

Just wondering if someone has a way to pause a macro in VBA? My macro is running a calculation that needs to be updated frequently, but by pausing, I am unable to work in Excel, and I need to work while the macro is on pause. The macro I have used is as follow:

...
For a = 0 To 100

'My calcs are all here...

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 10
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
If Application.Wait(Now + TimeValue("0:00:10")) = true Then
    End If
Next a

'Thanks
Reply With Quote
  #9 (permalink)  
Old May 30th, 2006, 12:23 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi Sebastien,

If you are wanting to update something frequently, a better way of doing it would be to add a timer control to the form, and set the update process to run on it. I haven't done one of these for a while, but let me know if you can't find any examples of how to do it, and I'll see if I can walk you through it.

Mike

Mike
EchoVue.com
Reply With Quote
  #10 (permalink)  
Old May 31st, 2006, 01:21 AM
Registered User
 
Join Date: May 2006
Location: Amsterdam, , Netherlands.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

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 07:10 AM.


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