Results 1 to 15 of 15
  1. #1
    stephen c is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    30

    Delay.

    Hi. I am trying to create a delay of longer than a couple of seconds, and came across this solution. It says to place this in the declarations:

    Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliseconds As Long)

    and then this in your regular code to call it (assuming 3 minutes):

    Call Sleep (180000)

    OK, so I think I get it. Access is using a Windows sleep functionality. No work will be done in Access for 3 minutes. I have no problem with that. What I don't understand is where the heck to put the "declaration." It's just something I've not had to do yet. I created a module in the database called Sleep, and inserted that code. Then, when I tried the "Call...." it doesn't work.

    Any explanation would be appreciated.

    Thanks!

    Stephen the newbie-ish

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    "Private" means the procedure can be called only from the module it is declared in.

    Place the declaration in a general module but change the Private to Public (or just remove Private) then the procedure can be called from anywhere in the database.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Why not set a variable stoptime as the current time and then loop until
    current time > dateadd("s"stoptime",180)

    Or similar.


    Sent from my iPhone using Tapatalk

  4. #4
    stephen c is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    30
    I tried June7's recommendation, and still get this error:
    Compile error: expected variable or procedure, not module.

    Here is exactly what I had done.
    1. Create a module, named it Sleep.
    2. The total contents of that module are:
    Option Compare Database
    Public Declare Sub Sleep Lib "kernel32" (ByVal lngMilliseconds As Long)
    3. In the code called by the button I have:
    Call Sleep (6000)

    Aaand error.

    Any ideas? I'm sure I'm doing something basic wrong.

    Thank you!

    Stephen.

  5. #5
    stephen c is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    30
    Hi, Andy. Thank you for your reply. I have been told not to do that, because it absorbs resources, particularly for longer wait times.

  6. #6
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Are you running 32 bit or 64 bit windows


    Sent from my iPhone using Tapatalk

  7. #7
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Change your sleep module so it's called something else. It's confusing access. The name of the module you store the sub in doesn't matter


    Sent from my iPhone using Tapatalk

  8. #8
    stephen c is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    30
    Hi Andy. Changed the name. Im on 64 bit. Aargh. Should that then say kernel64?

  9. #9
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    No add ptrsafe before the word sub


    Sent from my iPhone using Tapatalk

  10. #10
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    see this link to help

  11. #11
    stephen c is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    30
    Thank you guys for all of your help. Now, the delay works! (Andy, I didn't add prtsafe yet, because I'm not sure exactly where. I did so in the declarations and got error)

    Now, the odd thing is that the thing I'm waiting on doesn't execute until AFTER the delay! See full code below. What is supposed to happen is the program checks a record for the presence of the checkbox=true. If so, it incriments i, displays the new value in the textbox checkqty, then a delay, then on to the next record to check for i. I'm using the msgbox just as a test feature. I know this is a ridiculous program. In the future, "check for i" will be replaced with a call to an outside JAR, so this is just for mock-up.

    I have no idea why the value would wait until after the delay to display! Thanks, folks!

    --------------------

    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM consolidatorlisttable;")
    Dim i As Integer
    Dim starttime As Date
    i = 0
    rs.MoveFirst
    Do While Not rs.EOF And Not rs.BOF
    If rs!portalsend = True Then i = i + 1
    rs.MoveNext
    Loop

    Me.checkqty = i 'displays the value in i in the textbox checkqty

    Call Sleep(15000)

    ' starttime = Now
    'Do While DateDiff("s", starttime, Now) < 60
    'Loop

    MsgBox "test message"
    rs.Close
    Set rs = Nothing

  12. #12
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Quote Originally Posted by stephen c View Post
    Thank you guys for all of your help. Now, the delay works! (Andy, I didn't add prtsafe yet, because I'm not sure exactly where. I did so in the declarations and got error)

    Now, the odd thing is that the thing I'm waiting on doesn't execute until AFTER the delay! See full code below. What is supposed to happen is the program checks a record for the presence of the checkbox=true. If so, it incriments i, displays the new value in the textbox checkqty, then a delay, then on to the next record to check for i. I'm using the msgbox just as a test feature. I know this is a ridiculous program. In the future, "check for i" will be replaced with a call to an outside JAR, so this is just for mock-up.

    I have no idea why the value would wait until after the delay to display! Thanks, folks!

    --------------------

    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM consolidatorlisttable;")
    Dim i As Integer
    Dim starttime As Date
    i = 0
    rs.MoveFirst
    Do While Not rs.EOF And Not rs.BOF
    If rs!portalsend = True Then i = i + 1
    rs.MoveNext
    Loop

    Me.checkqty = i 'displays the value in i in the textbox checkqty
    docmd.requery "checkqty" might help
    Call Sleep(15000)

    ' starttime = Now
    'Do While DateDiff("s", starttime, Now) < 60
    'Loop

    MsgBox "test message"
    rs.Close
    Set rs = Nothing

    Try requerying the textbox to pick up the new value

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Don't think textbox can be requeried, at least I get 'does not support property or method' error. What exactly would be requeried in a textbox? It does not have a query like a combobox or listbox or form. A form can be refreshed but that doesn't help either. Interesting, I set a breakpoint on the Sleep() call and the value immediately shows in the textbox.

    I don't think there is a fix for this.

    Why do you need delay?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    stephen c is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2009
    Posts
    30
    Andy and June, first, thank you so much for your help. Part of my reason for wanting to understand the delay, and how things display is general learning. That said, this is a simplistic example of what I'm trying to build. The end result is that each loop will, instead of increasing the value of i and displaying it, will actually launch a JAR. That JAR needs time to run before the next one is launched (if the box is checked.) A better solution would be to have the folder with the JAR in it hold an app.bat.end file. The JAR will delete that file while running, and then recreate it when it closes. There would be no timing to consider, IF I could figure out how to get Access to test for the presence of that file. I think I'll start a new tread for that one!

  15. #15
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Np Stephen. Access can test easily if a file exists. Just search this forum.


    Sent from my iPhone using Tapatalk

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Network delay
    By KoMiKo in forum Programming
    Replies: 2
    Last Post: 01-29-2016, 12:50 AM
  2. Replies: 3
    Last Post: 02-09-2015, 02:41 PM
  3. Sending Email with Delay
    By cbrsix in forum Programming
    Replies: 3
    Last Post: 08-06-2013, 08:08 AM
  4. Delay in the result
    By markyboy in forum Forms
    Replies: 1
    Last Post: 05-25-2011, 09:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums