Create an ADO connection to the database
Printer Friendly Page
- This module can be used in any application to set up a database connection:
- Set the variable gConn as Public to enable any form
or module to access the ADO connection
- If the data connection is successful, send back a response of TRUE.
Public gConn As New ADODB.Connection
Public Function DataOpen() As Boolean
On Error GoTo open_EH
gConn.CursorLocation = adUseClient
gConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;_
Data Source=C:\Products\Products.mdb;"
gConn.Mode = adModeReadWrite
gConn.Open
DataOpen = TRUE
open_EH:
Call ErrorHandler(gConn)
DataOpen = FALSE
Exit Function
End Function
Public Sub ErrorHandler(gConn As Connection)
Dim oErr As Error
Dim strMsg As String
For Each oErr in gConn.Errors
strMsg = strMsg & "Error #: & oErr.Number & vbCrLf
strMsg = strMsg & "Description: " & oErr.Description & vbCrLf
strMsg = strMsg & "Source: " & oErr.Source & vbCrLf
Next
MsgBox strMsg
End Sub