By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

Test Internet Connection from within Access

100+
P: 759
Can I test the Internet Connection from within Access ?

I have a hyperlink field that contains URLs to web pages.
I like to test if the computer can access the Internet in order to enable/disable the control "GoToThisPage" in the related form.

Can that be done ? How ?

Thank you !
Nov 10 '12 #1

✓ answered by ADezii

The API can easily tell you as to whether or not you are connected to the Internet:
Expand|Select|Wrap|Line Numbers
  1. Public Declare Function InternetGetConnectedState Lib "wininet.dll" _
  2. (ByRef dwflags As Long, ByVal dwReserved As Long) As Long
Expand|Select|Wrap|Line Numbers
  1. Public Function GetInternetConnectedState() As Boolean
  2.   GetInternetConnectedState = InternetGetConnectedState(0&, 0&)
  3. End Function
Expand|Select|Wrap|Line Numbers
  1. Dim strConnected As String
  2.  
  3. strConnected = IIf(GetInternetConnectedState(), "Connected", "NOT CONNECTED")
  4.  
  5. MsgBox strConnected, vbInformation, "Internet Connected Status"

Share this Question
Share on Google+
9 Replies


Rabbit
Expert Mod 10K+
P: 12,366
You can ping the address and see if that's successful.
Nov 11 '12 #2

zmbd
Expert Mod 5K+
P: 5,397
Ping may not work 100% depending on the host file list, proxy, or other I.T. interferences.

For example... if I try to ping the IP for MSN at work... the ping will fail because the company DSN server traps all direct IP access; however, if I use the URL I Can connect without issue (well... unless the Internet is down)

What I have done is use automation to create an IE object, navigate to a known webpage and wait for the ready state to show valid. Requires the references for IE which adds some overhead but not much.

I've also ran across the "wininet.dll" and some code to use it; however, I've not had the time to really determine the usage so I'm not sure if it has the same issues as I've ran into with my I.T. - but it looks promising as there appears to be proxy detection.
Nov 11 '12 #3

100+
P: 759
Thank you both for answers !
I'll try the suggestions and I'll inform you about the results.
Nov 12 '12 #4

ADezii
Expert 5K+
P: 8,638
The API can easily tell you as to whether or not you are connected to the Internet:
Expand|Select|Wrap|Line Numbers
  1. Public Declare Function InternetGetConnectedState Lib "wininet.dll" _
  2. (ByRef dwflags As Long, ByVal dwReserved As Long) As Long
Expand|Select|Wrap|Line Numbers
  1. Public Function GetInternetConnectedState() As Boolean
  2.   GetInternetConnectedState = InternetGetConnectedState(0&, 0&)
  3. End Function
Expand|Select|Wrap|Line Numbers
  1. Dim strConnected As String
  2.  
  3. strConnected = IIf(GetInternetConnectedState(), "Connected", "NOT CONNECTED")
  4.  
  5. MsgBox strConnected, vbInformation, "Internet Connected Status"
Nov 18 '12 #5

zmbd
Expert Mod 5K+
P: 5,397
ADezii
THANK YOU!
That makes me feel better about that API call... the code you posted is very similar to what I had found; however, I didn't understand it completely and I don't like to suggest something I don't understand.
Nov 18 '12 #6

ADezii
Expert 5K+
P: 8,638
@zmbd:
Glad that everything was cleared up for you - my pleasure.
Nov 18 '12 #7

NeoPa
Expert Mod 15k+
P: 31,492
If you have Windows API needs then there's a good chance that ADezii will be your man. He's done a lot of work in that area and has experience with all sorts of requirements :-)
Nov 18 '12 #8

100+
P: 759
May I use this even if I don't understand very well ?
Thank you ADezii ! Good job !
Nov 19 '12 #9

ADezii
Expert 5K+
P: 8,638
You are quite welcome, Mihail. You most certainly can use this functionality even if you do not fully understand the Code. The Code can actually be simplified by DELETING the Function altogether, eliminating the IIf() Construct, and making the API Call directly as in:
Expand|Select|Wrap|Line Numbers
  1. If InternetGetConnectedState(0&, 0&) Then
  2.   MsgBox "Connected"
  3. Else
  4.   MsgBox "NOT Connected"
  5. End If
P.S. - You would still need the API Declaration, namely:
Expand|Select|Wrap|Line Numbers
  1. Public Declare Function InternetGetConnectedState Lib "wininet.dll" _ 
  2. (ByRef dwflags As Long, ByVal dwReserved As Long) As Long
Nov 19 '12 #10

Post your reply

Sign in to post your reply or Sign up for a free account.