title: Error Handling in VBA when Connection is not present
body: <p>I'm trying to put together a simple macro that does the following.</p>
  
  <ul>
  <li>Unlocks my password protected sheet</li>
  <li>Refresh a Query (Obtains info from an Access database on network drive)</li>
  <li>locks sheet with password.</li>
  </ul>
  
  <p>I've put in an error handler to simply relock the spreadsheet and prompt a message box.  However that error handler doesn't work when there is no internet connection. It works fine if there is a network connection, and say for example I've moved the Access Database to a different location than the one stored in the Query.</p>
  
  <p>I get a Run-time error 1004:
  [DataFormat.Error] Your Network access was interrupted.  To continue, close the database, and them open it again.</p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>Sub RefreshItemTable()
  
      ActiveSheet.Unprotect Password:="password"
  
      Worksheets("Item List").Range("A1").ListObject.QueryTable.Refresh
  
      On Error GoTo connError
  
      DoEvents
  
      ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True _
          , AllowFormattingColumns:=True, AllowFiltering:=True
  
      Exit Sub
  
      connError:
      ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True _
          , AllowFormattingColumns:=True, AllowFiltering:=True
      MsgBox ("Unable to Connect")
  
  End Sub
  </code></pre>