Testing a DSN





5
Date Submitted Fri. Aug. 25th, 2006 4:23 AM
Revision 1 of 1
Helper Cyber-Drugs
Tags Private
Comments 0 comments
Below is the code you can use in Access Database Forms, to test a DSN connection. Handy if you want to link some of your Forms to another database via DSN.

Private Sub Command0_Click()
    Dim adoConn As ADODB.Connection
    Dim adoRecSet As ADODB.Recordset
   
    On Error GoTo ConnectError
        Set adoConn = New ADODB.Connection
        adoConn.Open "JustinDSN", "myuser", "mypass"
    Exit Sub
   
ConnectError:
        MsgBox "Could not connect to Server"
    Exit Sub
   
    If adoConn.State = 1 Then
        MsgBox "Connection Successful"
    Else
        MsgBox "Connection Un-Successful"
    End If
   
    adoConn.Close
    Set adoConn = Nothing
End Sub
 

Justin Nel

Comments

There are currently no comments for this snippet.

Voting