Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2002
    Location
    Sydney
    Posts
    21

    Unanswered: How do I do a 'nice' time delay?

    Hi all.

    I'm doing some code that:

    - goes through a table
    - opens up a report ( single page ) based on an ID in each record
    - prints it to a PDF writer
    - *** waits until PDF writer is finished ***
    - picks up the PDF
    - dumps it in an appropriate directory
    - stores details of the PDF in another table
    - goes to the next record

    The PDF writer is Ghostscript, with a Redirection Port Monitor hook into Windows' printing.

    Anyway, the problem is that Access is trying to get the PDF before Ghostscript has had time to do anything. I need to make Access relax for a couple of seconds while Ghostscript has time to fire up and do something. I've tried doing a 'busy wait' by making Access count to 100,000, but with Windows' lovely multitasking, Access seems to get 99% of the CPU, so even when it gets to the end of the loop, Ghostscript still hasn't had a chance to do it's work. Is there a 'wait' command or something that will make Access wait & give up the CPU?

    I've also had a brief look at putting an 'on timer' event on a form and manipulating that for my time delay, but this seems to produce the same problem: setting the 'on timer' event makes Access hog the CPU.

    Anyone got any ideas?

  2. #2
    Join Date
    Aug 2003
    Location
    UK
    Posts
    78
    On the forms there is a built in timer. You can set the timer in milli seconds ie 1000 = 1 sec then in the on timer section you can write your code. Hope this helps.
    the light is on, someone is home, but they dont know they are. HELLO!

  3. #3
    Join Date
    Feb 2002
    Location
    Sydney
    Posts
    21
    Yeah I know about the timer event. It chews up the CPU ( busy wait ) in the same way that counting to 100,000 chews up the CPU. I need the CPU to be available during the wait so Ghostscript can have enough cycles to create the PDF.

    Thanks for the response anyway

  4. #4
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Try this API

    Private Declare Sub sapiSleep Lib "kernel32" _
    Alias "Sleep" _
    (ByVal dwMilliseconds As Long)

    Sub sSleep(lngMilliSec As Long)
    If lngMilliSec > 0 Then
    Call sapiSleep(lngMilliSec)
    End If
    End Sub

    Sub sTestSleep()
    Const cTIME = 1000 'in MilliSeconds
    Call sSleep(cTIME)
    MsgBox "Before this Msgbox, I was asleep for " _
    & cTIME & " Milliseconds."
    End Sub

  5. #5
    Join Date
    Aug 2003
    Location
    UK
    Posts
    78
    how about DoEvents.
    In Microsoft Access, the DoEvents function is ignored if you use it in:

    A user-defined function or a procedure that calculates a field in a query, form, or report.
    A user-defined function that creates a list to fill a combo box, a list box, or an OLE object.

    If you include the DoEvents function in any of these, Microsoft Access will not relinquish control to the operating system.

    hope this helps
    Last edited by dapman2002; 11-14-03 at 04:56.
    the light is on, someone is home, but they dont know they are. HELLO!

  6. #6
    Join Date
    Feb 2002
    Location
    Sydney
    Posts
    21
    Originally posted by hammbakka
    Try this API

    Private Declare Sub sapiSleep Lib "kernel32" _
    Alias "Sleep" _
    (ByVal dwMilliseconds As Long)

    Sub sSleep(lngMilliSec As Long)
    If lngMilliSec > 0 Then
    Call sapiSleep(lngMilliSec)
    End If
    End Sub

    Sub sTestSleep()
    Const cTIME = 1000 'in MilliSeconds
    Call sSleep(cTIME)
    MsgBox "Before this Msgbox, I was asleep for " _
    & cTIME & " Milliseconds."
    End Sub
    Hammbakka,

    You are a God!
    Exactly what I needed.
    Thankyou.

  7. #7
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Originally posted by VanDan
    Hammbakka,

    You are a God!
    Exactly what I needed.
    Thankyou.
    Never mind, main thing it functions

    Good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •