Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for Connection 1

Status
Not open for further replies.

sap2

Technical User
Dec 20, 2007
12
US
Scenario:
FE database on laptop that has linked tables to the server. AutoExec macro initiates the links. My problem is that if not connected to the server the db fails because it cannot find the links.

1. How can it check for a proper link prior to running the AutoExec macros?

2. If a connection IS NOT found then ignore linking the tables.

3. If a connection IS found then continue with the links.

Thanks for any help.
 
this function will test connection but if you are not connected runs sluggish.

Code:
'/////Form Code add a commanbutton// and paste//////////
Private Sub Command1_Click()
    MsgBox TestInternetConnection
End Sub

'/////////////////////////Place in module//////////////
Option Explicit


Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal lpszAgent As String, ByVal dwAccessType As Long, ByVal lpszProxyName As String, ByVal lpszProxyBypass As String, ByVal dwFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInet As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Long

Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Const INTERNET_FLAG_KEEP_CONNECTION = &H400000
Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000

Public Function TestInternetConnection() As Boolean
    Dim sTmp As String
    Dim hInet As Long
    Dim hUrl As Long
    Dim Flags As Long
    Dim url As Variant
    hInet = InternetOpen(App.Title, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)

    If hInet Then
        Flags = INTERNET_FLAG_KEEP_CONNECTION
        hUrl = InternetOpenUrl(hInet, "[URL unfurl="true"]http://www.yahoo.com",[/URL] vbNullString, 0, Flags, 0)
        If hUrl Then
           'Your computer is connected to Internet
           TestInternetConnection = True
        Else
          'Your computer is not connected to Internet
          TestInternetConnection = False
        End If
    End If
    
    Call InternetCloseHandle(hInet)
   
End Function

[wink]
 
>AutoExec macro

This suggests that future enquiries might be better made in forum707
 
three57m - being connected to the Internet does not mean I have access to any particular server. I could have access to a server without an Internet connection if I have a physical connection to it (LAN). Alternatively, I could have Internet access but not be able to reach a server (for example, I might not have established a VPN connection).

Here's a little function that should tell you if a link works on a particular table (in this case a table called "Test")
Code:
Public Function IsTableConnected() As Boolean
    On Error GoTo ErrHandler
    
    CurrentDb.TableDefs("Test").RefreshLink
    
    IsTableConnected = True
    
    Exit Function
    
ErrHandler:
    IsTableConnected = False
    
End Function
Of course one can't help but note that if you add a few more lines of code (hint: loop through all TableDefs) and you could pretty much replace the macro alltogether.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top