送你一个数据联接类
Option Explicit
Private Cn As ADODB.Connection
Private Rs As ADODB.Recordset
Private Cm As ADODB.CommandPublic Function getWriteRs(ByVal SourceVal As String) As ADODB.Recordset
    With Rs
        If .State = adStateOpen Then .Close
        .Source = SourceVal
        .CursorType = adOpenStatic
        .LockType = adLockPessimistic
        .Open
        Set getWriteRs = Rs       '传可读写记录集
    End With
End FunctionPublic Function getReadRs(ByVal SourceVal As String) As ADODB.Recordset
    Cm.CommandText = SourceVal
    Set getReadRs = Cm.Execute      '传可只读记录集
End FunctionPublic Sub runCommand(ByVal ExecuteVal As String)         '执行命令
        Cm.CommandText = ExecuteVal
        Cm.Execute
End SubPrivate Sub Class_Initialize()  '打开连接
    Set Cn = New ADODB.Connection
    'Cn.ConnectionString = "dsn=Exam;" '"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\MYWORK\Exam.mdb;"
    Cn.Open "dsn=Exam", "wu", "123"
    
    Set Rs = New ADODB.Recordset
    Rs.ActiveConnection = Cn
    
    Set Cm = New ADODB.Command
    Cm.ActiveConnection = Cn
End SubPrivate Sub Class_Terminate()   '回收
    If Rs.State = adStateOpen Then Rs.Close
    
    Set Rs = Nothing
    Set Cm = Nothing
    Cn.Close
    Set Cn = Nothing
End Sub