Results 1 to 2 of 2

Thread: Detect Timeout?

  1. #1

    Thread Starter
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Detect Timeout?

    I have an Excel sheet with a simple macro that uploads the information on the sheet to a local Access DB.

    Code:
    Dim cn As Object
        Dim rs1 As String, scn As String, dbWb As String, dsh As String
        Dim ssDelete As String, ssql As String
        Dim rng As Range
        
        Set rng = rInput.CurrentRegion
        Set cn = CreateObject("ADODB.Connection")
        
        dbWb = Application.ActiveWorkbook.FullName
        scn = "Provider=" & strPROVIDER & ";Data Source=" & ActiveWorkbook.Path & "\" & strDB
        ssql = "INSERT INTO " & strTable & " "
        dsh = "[" & rng.Parent.Name & "$" & rng.Address(False, False) & "]"
        ssql = ssql & "SELECT * FROM [" & ExcelDriver & ";HDR=YES;DATABASE=" & dbWb & "]." & dsh
        ssDelete = "delete * from [" & strTable & "];"
        
        With cn
            .Open scn
            If flg = True Then .Execute ssDelete
            .Execute ssql
            .Close
        End With
        
        Set cn = Nothing
    The Access DB is set up such that it automatically updates a SharePoint list. If there is a connection issue to SharePoint (e.g. expired credentials), the Excel file just sits in a hung state and never completes its task. I'd like to know if there is some way I can time the request to update the Access DB and abort the command if a pre-determined timeout threshold is exceeded. Right now, the user has to kill the Excel application from the Task Manager which isn't very elegant.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Detect Timeout?

    have you tried using a timer to detect how long the macro has been running and if need be end or close excel
    i doubt there is any less extreme method to terminate the code, though a stop statement may allow you to break all code in the IDE
    i believe you may be able to change the timeout value for ADO, but if it is just hanging that may not make any difference
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width