Results 1 to 4 of 4

Thread: Wasting Time

  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    I've got several users updating the same database at the same time using a loop in a DAO recordset. Occassionally I hit a record that is locked but a second later it will process OK.

    What is the best way to waste a second before I retry.

    Code:
            intRetries = 0
        strAction = "Update Server Record"
        Set rstServer = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
        ' *** for each record add or update ***
        If rstServer.EOF Then
            rstServer.AddNew
        Else
    Retry_Edit:
            rstServer.Edit
        End If
        For Each fld In rstLocal.Fields
            strFieldName = fld.Name
            rstServer(strFieldName) = rstLocal(strFieldName)
        Next
        rstServer.Update
    Exit_Procedure:
        On Error Resume Next
        Exit Function
    Error_Handler:
        Select Case strAction
            Case "Update Server Record"
                If intRetries < 5 Then
                    intRetries = intRetries + 1
                    'waste some time
                    Resume Retry_Edit
                end if
            Case Else
                    
        End Select
        MsgBox "Error: " & Err.Number & "; Description: " & Err.Description, vbCritical, DBEngine(0)(0).Properties("AppTitle")
        Resume Exit_Procedure
        Resume  'used for debugging

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    The two options that come to mind are DoEvents or Sleep.

    You can read about them here
    Regards
    John



  3. #3
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You could use a Timed Do Loop to put a pause in for a specific duration

    eg
    Code:
    'Define at the Start
    Dim dteTime As Date, dteWait As Date
    
    dteWait = TimeValue("00:00:05")    'Is 5 Seconds
    
    'Then Put in a Timed Pause
    dteTime = Time
    Do Until Time >= dteTime + dteWait
    Loop
    
    'Continue Code
    Andrew

  4. #4
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    Nice, thanks John and Andrew. and Luke

Posting Permissions

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