internet handing error

medic5678

Board Regular
Joined
Nov 13, 2018
Messages
67
Hi everyone. My application does a data query on an internet site. When the internet isn't functioning, I'm getting the following error message"

runtime error

[DATAFORMAT.ERROR]
THE SERVER OR PROXY WASN'T FOUND

I would like to trap this specific error and allow the user to manually input the data and continue with the program. We lose internet access daily and it's essential that we can continue to process if the internet is down.

If the error is another error of any sort, I want to tell the user there has been an error and they need to start excel again. Very occasionally, I will get what appears to be a random error to me. It's simple enough to restart excel should this happen. I will eventually address this issue, but as a practical matter, it happens so rarely it's not worth addressing at this time. Data integrity is not an issue here. So I just want to put up a message box and tell them excel will have to be started over.

Thanks!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
hi. rather than have your program falling over due to errors, it is better programming practice to pre-empt likely errors. so one solution would be to check if the internet is connected prior to executing the query.

declare this at the top of your module outside any subs
VBA Code:
Private Declare PtrSafe Function InternetGetConnectedState Lib "wininet.dll" (ByRef dwflags As Long, ByVal dwReserved As Long) As Long

and this sample demonstrates how to incorporate the line in your code
VBA Code:
Sub Test()
    Dim NetActive As Boolean
    NetActive = InternetGetConnectedState(0&, 0&)
   
    MsgBox "internet status is " & NetActive
    If NetActive Then
        ' do the query
       ....
    End If
End Sub
 
Upvote 0
Sub Test() Dim NetActive As Boolean NetActive = InternetGetConnectedState(0&, 0&) MsgBox "internet status is " & NetActive If NetActive Then ' do the query .... End If End Sub
Absolutely brilliant! Worked like a charm. You have expanded my bag of tricks. Much appreciated!
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top