Class clsADO Private m_objConn '// Connection object Private m_objRS '// Recordset object Private m_strConnection '// Type of database Private m_intLockType '// Recordset Lock Type Private m_intCursorLocation '// Recordset Cursor Location Private m_intCursorType '// Recordset Cursor Type Private m_strErrorMessage '// Return a human readable error message Private adStateOpen '// PROPERTIES Public Property Let LockType(intLockType) m_intLockType = intLockType End Property Public Property Let CursorLocation(intCursorLocation) m_intCursorLocation = intCursorLocation End Property Public Property Let CursorType(intCursorType) m_intCursorType = intCursorType End Property Public Property Get ErrorMessage() ErrorMessage = m_strErrorMessage End Property '// -------------------------------------------------- '// Initialise the ADO objects '// -------------------------------------------------- Private Sub Class_Initialize() On Error Resume Next '// Set default properties m_intLockType = 2 'adLockPessimistic m_intCursorLocation = 2 'adUseServer m_intCursorType = 0 'adOpenForwardOnly m_strConnection = "" m_strErrorMessage = "" adStateOpen = &H00000001 If IsEmpty(m_objConn) Then Set m_objConn = CreateObject("ADODB.Connection") End If If IsEmpty(m_objRS) Then Set m_objRS = CreateObject("ADODB.Recordset") End If End Sub '// -------------------------------------------------- '// Class_Terminate() '// -------------------------------------------------- Private Sub Class_Terminate() On Error Resume Next m_objRS.Close Err.Clear Set m_objRS = Nothing Set m_objConn = Nothing End Sub '// -------------------------------------------------- '// Connection to Data Source '// -------------------------------------------------- Public Sub Connect(ByVal strConnection) On Error Resume Next '// Open the connection With m_objConn If .State = adStateOpen Then .Close End If .ConnectionString = strConnection .Open Dim er m_strErrorMessage = "" For Each er In .Errors If er.number <> 0 Then m_strErrorMessage = m_strErrorMessage & "Error#" & CStr(er.number) & " - " & er.description & vbCrLf Next End With End Sub '// -------------------------------------------------- '// Retrieve the data and return them in requested form. '// -------------------------------------------------- Public Function ExecuteSQL(ByVal strSQL) On Error Resume Next If Not (IsNumeric(m_intLockType) Or IsNumeric(m_intCursorLocation) Or IsNumeric(m_intCursorType)) Then m_strErrorMessage = "Invalid parameter" Exit Function End If '// Set proper ties for the recordset object With m_objRS If .State = adStateOpen Then .Close End if .CursorType = m_intCursorType .CursorLocation = m_intCursorLocation .LockType = m_intLockType .ActiveConnection = m_objConn .Source = strSQL .Open '// Return recordset '// Set this function as a pointer to the recordset. Set ExecuteSQL = m_objRS End With End Function '// -------------------------------------------------- '// Close the connection and recordset object '// -------------------------------------------------- Public Sub Close() '// Close the connection With m_objConn If .State = adStateOpen Then .Close End If End With '// Close the recordset object With m_objRS If .State = adStateOpen Then .Close End if End With End Sub End Class