Results 1 to 8 of 8
  1. #1
    mcucino is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Jul 2017
    Location
    Providence, RI
    Posts
    74

    How to timeout a subroutine while it's running

    I have some slow running code and I'm trying to bypass the records in the loop causing the code to run slowly. Some of the records take 45+ minutes to calculate. Is there a way to set a timeout, where it will try to calculate the value, but if it doesn't calculate within 30 seconds, move to the next record?

    Code:
    Public Sub SpeedTest(Rpt As Long)
    Dim rs As dao.Recordset
    Dim db As dao.Database
    Dim b As Date
    
    
        [TempVars]![tv_currentID] = Rpt
        RunSQL "Delete * from SpeedTestT"
        RunQuery "SPeedtestMTq"
        Set db = CurrentDb
        Set rs = db.OpenRecordset("SELECT * FROM SpeedTestT;")
        
        If Not (rs.EOF And rs.BOF) Then
            rs.MoveFirst
            Do Until rs.EOF = True
                rs.Edit
                b = Now()
                rs!starttime = b
                rs!Equals = Eval(rs![Equation])
                rs!ttc = Round((Now() - b) * 24 * 60, 5)
                rs.Update
                rs.MoveNext
            Loop
        End If
        
        rs.Close
        db.Close
        
        Set rs = Nothing
        Set db = Nothing
    End Sub


  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Not that I know of. Really should figure out why some records take so long to calculate.
    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
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    According to here http://allenbrowne.com/AppIssueBadWord.html#E
    Equals is a reserved word. Also, should be rs!update, not rs.Update?
    Probably not the reasons why, but worth a shot. How do you know it is "some" of the records that take a long time as opposed to all of them? Or are you not referring to within a given set of records, but some sets and not others?
    Also looks like you're using a function to run a query. I take it this is not just a Select query (if it is, it's probably a waste of time and resources).
    I get the rs.Close, but not db.Close.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by Micron View Post
    . Also, should be rs!update, not rs.Update?
    I have half bottle of wine in me, but I think not. Generally, bang would refer to a field, dot to a method. The .Update "closes off" the .Edit. In other words, it commits the edited data.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Code:
        RunSQL "Delete * from SpeedTestT"
        RunQuery "SPeedtestMTq"
    Shouldn't that be Docmd.RunSql?
    I have never seen "RunQuery". Shold that be DoCmd.OpenQuery?

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Tell us about the record and calculation that is taking 45+ minutes to execute.
    Do you test your proposed calculation and get it "optimized" before going to "production mode"?

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Quote Originally Posted by moke123 View Post
    I have never seen "RunQuery". Shold that be DoCmd.OpenQuery?
    No doubt a function call as I suggested. I've used something similar before. In fact, you will find that exact procedure name in code posted elsewhere.

  8. #8
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    It was actually RunSql, a method, that caught my eye.

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

Similar Threads

  1. where to set timeout ?
    By vientito in forum Access
    Replies: 1
    Last Post: 10-21-2014, 08:23 AM
  2. Query not running right in subroutine
    By Historypaul in forum Programming
    Replies: 8
    Last Post: 01-29-2013, 06:42 AM
  3. Timeout Expired
    By Raj in forum Access
    Replies: 3
    Last Post: 05-04-2011, 09:51 PM
  4. Calling Access VBA subroutine from an Excel VBA subroutine
    By richard_yolland in forum Programming
    Replies: 0
    Last Post: 02-16-2011, 11:30 AM
  5. Timeout Expired
    By brvaland in forum Database Design
    Replies: 0
    Last Post: 04-03-2009, 04:12 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