title: Internet connectivity check - Access VBA
body: <p>So, I have been on this for much longer than anticipated as to first finding out about this function, whilst it works great for being offline (a lack of a wifi or ethernet based connection) it is very hazy when determining if connected to the internet.
  <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384702(v=vs.85).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/windows/desktop/aa384702(v=vs.85).aspx</a></p>
  
  <p>The example case would be if there is a log in screen you would typically find at any coffee shops or hotel, or worse yet if connected to a wifi network with no internet connection, it will give back a result of online?!</p>
  
  <p>Now, the desired function of mine is to give a very reliable return of 3 cases, definitely online, definitely offline, diagnose the issue on network (if connected via ethernet or wifi with no internet connection, including but not limited to disconnected ethernet at switch, wan ethernet port disconnected, hotel wifi, public wifi with log in etc etc) </p>
  
  <p>2 known error codes thrown as a result of being "offline completely" whereby there is not a ethernet cable plugged in, or any wireless connection active; the second being for being on any network but not having a live web connection.</p>
  
  <p><strong>Now as to the problem</strong></p>
  
  <p>I have fully functioning code, however with my large access database in case 3 as mentioned above, the forms or any function running at that freezes, from simply dragging around a print preview screen to typing, it will freeze.</p>
  
  <p>This is just not feasible with many background functions working, such as searches or other timers and it will cause problems when end users attempt to use something that constantly (every 10 seconds) would hang. Now I have already thought of the approach of changing the timer to every 5 minutes say, but that defeats the object here as I am attempting to continually show users especially within areas of intermittent internet connections that they are no longer connected. </p>
  
  <p>I have searched for amending the timeout period, but that vaguely resolves my problem, it maybe shaved 1 second at most on average across extensive testing. Currently leaving me on around 4-6 seconds of "Access is not responsive"</p>
  
  <p>To be clear, using my request response method is working fine in both simple cases of definitely online (obtains a response from a web page) and offline (instant timeout).</p>
  
  <p>How can I eradicate the .get from lagging access to a stand still, even in vba you cannot scroll up/down or try to amend anything unless outside the period of the timer (10 seconds) so it takes 4-6 seconds to process the "Diagnosis" case, outputting text as a small box on the form. </p>
  
  <pre><code>Public Function ConnectivityCheck(urlzzz) As Long
  
  On Error GoTo err_handler:
  Dim Resolve, Connect, Send, Receive As Integer
  Dim RequestResponse As XMLHTTP60
  Dim K As Integer
  Dim Parameter1 As String
  Dim Doc As DOMDocument60
  Set RequestResponse = New XMLHTTP60
  
  Set Doc = New DOMDocument60
  Set RequestResponse = CreateObject("Msxml2.ServerXMLHTTP.6.0")
  
      Resolve = 200     ' In Milliseconds, 4 Stages to a Request.statement each individually attuned timing before
      Connect = 350    '"timing" out/cancelling the request.
      Send = 350
      Receive = 350     'waiting time to receive data from server
      RequestResponse.setTimeouts Resolve, Connect, Send, Receive
  
  With RequestResponse
      .Open "GET", urlzzz, False
      .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
      .Send
      Doc.LoadXML .responseText
  End With
  Doc.LoadXML Doc.Text
  
  If InStr(RequestResponse.responseText, "example") Then
      K = 1
      ConnectivityCheck = K
      Debug.Print RequestResponse.responseText
  
  End If
  
  
  Exit Function
  err_handler:
      ConnectivityCheck = err.Number
      Debug.Print ConnectivityCheck
      If err.Number = -2147012894 Then
          Debug.Print "No internet connection" ' connected to some sort of network but no live web connection
      ElseIf err.Number = -2147012889 Then
      Debug.Print "Offline" 'simply unplugged or not connected to any wireless network
      End If
  End Function
  
  Public Sub testerrrr()
  Dim urlzzz As String
  urlzzz = "http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=example"
  ConnectivityCheck (urlzzz)
  
  End Sub
  </code></pre>
  
  <p>I appreciate any tips or pointers, even something basic I may have overlooked.</p>
  
  <p>Thanks.</p>