Here I'm trying to sleep the function below for 10 seconds so that if the internet is not connected it should move to the next code and provide a friendly message to the user so that the user knows exactly what is happening.
What is now happening
(1) If there no internet the code works ok and give the messages within the specified seconds
(2) If there is internet then the code will keep waiting for over 45 minutes which is causing long lines in our retails shops. This is where we need help to fix this.
What is now happening
(1) If there no internet the code works ok and give the messages within the specified seconds
(2) If there is internet then the code will keep waiting for over 45 minutes which is causing long lines in our retails shops. This is where we need help to fix this.
Code:
Dim Request As Object
Dim stUrl As String
Dim Response As String
Dim requestBody As String
stUrl = "http://localhost:8080/xxxxxxxxxxxxxxxxxxxx"
Set Request = CreateObject("MSXML2.XMLHTTP")
requestBody = strData
With Request
.Open "POST", stUrl, False
.setRequestHeader "Content-type", "application/json"
.Send requestBody
Response = .ResponseText
End With
Sleep (10000)
If Request.Status <> 200 Then
Resume Next
ElseIf Request.Status = 200 Then
MsgBox Request.ResponseText, vbInformation, "Internal Audit Manager"
Resume Next
End If
Option Compare Database
Option Explicit
#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If
Last edited: