Access VBADiscuss 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 .
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:
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
' Try opening file again.
Set oFile = fso.OpenTextFile("C:\LogCalls.txt", ForAppending, True)
'Write to text file.........................
Set oFile = Nothing
Set oFso = Nothing
Don't know if thats at all helpful, but might give you some ideas.
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.
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.
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)
If Application.Wait(Now + TimeValue("0:00:10")) = true Then
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.