I am trying to compile some simple VBA code to check internet connectivity of the PC before the execution of a subroutine that sends emails via remote SMTP server. I have found that Access freezes if it tries to send emails when not connected to the internet, hence the desire for a connectivity pre-check. The idea is that if there is no internet connection then Access does not attempt to send the emails. For testing purposes I am trying to develop the connectivity check code behind a command button click.
I have found a few articles that deal with checking internet connectivity in VBA, but nothing that I can get to work. I am trying to adapt the following code (from: https://bytes.com/topic/access/answers/944317-test-internet-connection-within-access
), which -if I can only get it to work- would seem to be the simplest solution:
Private Sub NetworkConnection_Click()
Public Declare Function InternetGetConnectedState Lib "wininet.dll" ()
0&, 0&) Then
MsgBox "Connected to internet"
MsgBox "Not Connected to internet"
When this is run, I get an error saying that "only comments can be written after End Sub, End Function or End Property". If anyone could help out on this I would be most grateful ! I am using MS Access 2013 / Windows 7 professional 64-bit.