Results 1 to 12 of 12

Thread: pause in code

  1. #1
    Join Date
    Aug 2004
    Posts
    178

    Unanswered: pause in code

    i need to put a a pause for about 30 sec to delay before it does anything else or would a for next loop do

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    No. It will get optimized away ... This ain't DOS anymore kiddo ...

    Try a "forever" loop testing 2 timestamps for your 30 sec difference.
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Just came across this delay function online yesterday! Haven't had time to test it, but you might give it a whack!
    '================================================= ==================
    ' NOTE: In Visual or Access Basic the unit of greatest precision
    ' is seconds. Therefore if the Timer is set to wait one second, the
    ' result could be a delay of anywhere from 0 to 1 second. If a higher
    ' degree of precision is required, another option is to use the Timer
    ' event of the form which has the ability to trigger every 1000th of a
    ' second.
    '================================================= ===================

    Function Wait(Delay As Integer, DispHrglass As Integer)

    Dim DelayEnd As Double
    DoCmd.Hourglass DispHrglass
    '(In Microsoft Access 2.0 and 1.x use: DoCmd Hourglass DispHrglass)
    DelayEnd = DateAdd("s", Delay, Now)
    While DateDiff("s", Now, DelayEnd) > 0
    Wend
    DoCmd.Hourglass False
    '(In Microsoft Access 2.0 and 1.x use: DoCmd Hourglass False)

    End Function

    Use like this:

    Wait 30, False

    Not sure what the "false" does! You might have to diddle with that also! Post back if it works for you!
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Aug 2004
    Posts
    178
    it works fine as is but its not the delay i need there is something else wrong

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Stick this code in a module. Do NOT call this module Pause.
    Code:
    Public Function Pause(NumberOfSeconds As Variant)
        
        Dim PauseTime As Variant, Start As Variant
        
        PauseTime = NumberOfSeconds
        Start = Timer
        
        Do While Timer < Start + PauseTime
            DoEvents
        Loop
    Then call the command as follows
    Code:
    Pause(5)
    the number you put in the brackets is the length of the pause.
    George
    Home | Blog

  7. #7
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    George,

    Couple of things:

    What is "Timer"? Where is it defined?

    If Timer is a date then you're adding 5 to it (your example). How do you know that the addition is going to be only 5 seconds? It could be be days ...
    Back to Access ... ADO is not the way to go for speed ...

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Stick your cursor in the word Timer and hit F1
    You'll see that it does not need user definition because it is a built in function.

    Any more Qs?
    George
    Home | Blog

  9. #9
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by georgev
    Stick your cursor in the word timer and hit F1
    You'll see that it does not need user definition because it is a built in function.
    Ah ... In what version. I mean you could use Now() for that matter ...

    Just a little tip in this access forum: Don't assume a particular version. This place runs the gamut from A97 to A2003 ... And just try keeping all the various feature options for each generation straight in your head. Talk about a headache ...
    Back to Access ... ADO is not the way to go for speed ...

  10. #10
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    I count 4 different answers here.

    Which begs the question:
    Which one is the fastest?

    Inspiration Through Fermentation

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    When I got the e-mail notification for your post RNG I was ready to have a right old go!

    Funny guy... funny guy...

    @ Owen, yes you could indeed use Now() but then if you add 5, do you add days, hours, minutes? Timer function works in seconds, which is just prettier for this situation IMO
    And I believe Timer is supported back to 97... but someone should prove me wrong on that right about...
    George
    Home | Blog

  12. #12
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by georgev
    When I got the e-mail notification for your post RNG I was ready to have a right old go!

    Funny guy... funny guy...

    @ Owen, yes you could indeed use Now() but then if you add 5, do you add days, hours, minutes? Timer function works in seconds, which is just prettier for this situation IMO
    And I believe Timer is supported back to 97... but someone should prove me wrong on that right about...
    Hmmmm ... I stand corrected. Looks like I forgot about this one ... I do have some recollections on contemplating using the Timer function tho ... Outta sight, outta mind I guess ...
    Back to Access ... ADO is not the way to go for speed ...

Posting Permissions

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