Reputation: 293
I have a code snippet that checks if there is an internet connection. If it fails it goes into the error handler and opens a form with some text and a button.
This is a very complex code (not mine).
I want to halt the execution of the code in this function, and to resume it when the button in the other form is pressed.
Internet research has not been helpful. I have no idea how two different code parts could interact.
On Error GoTo NoConnnectionErrorHandler
Dim Request As New MSXML2.XMLHTTP60
Request.Open "GET", "http://www.bbc.com"
Request.send
'MsgBox Request.Status
NoConnnectionErrorHandler:
DoCmd.OpenForm "Frm_Global_NoConnectionDialog"
When there is no connection to the internet a form opens. How do I stop the code and let it resume when a button in another form is pressed?
It goes through the whole function (where the snippet is only a small part) periodically and checks.
When there is no connection it should halt the whole program, until the button is pressed, and then check the connection again and proceed if there is one.
EDIT: The answer tackles on the problem, but one thing that confuses me is how to trigger the "resume code execution" from a different form via a button press.
Upvotes: 1
Views: 243
Reputation: 10139
If I am understanding you correctly, you should use Exit Sub
above your error handler (NoConnectinoErrorHandler
).
Add some code to ensure your error has been resolved, then clear the error and resume your work.
See if this is what you are looking for:
Sub foo()
' Your unseen code ...
On Error GoTo NoConnnectionErrorHandler
Dim Request As New MSXML2.XMLHTTP60
Request.Open "GET", "http://www.bbc.com"
Request.send
'MsgBox Request.Status
Exit Sub 'Put this above your error handler
NoConnnectionErrorHandler:
DoCmd.OpenForm "Frm_Global_NoConnectionDialog"
'Some code to ensure error no longer exists....
Err.Clear
Resume
End Sub
Upvotes: 1