vb中ADODB.Connection___小问题

来源:百度知道 编辑:UC知道 时间:2024/05/12 16:25:29
我有两个窗体分别为Form1和Form2
在模块中定义了公共对象Dim Conn As ADODB.Connection
想实现在Form1中连接上一个数据库
在Form2中断开与此数据库的连接

How to do this?

Thanks you guys@!

模块
Private conn As New ADODB.Connection
Public Sub OpenConn()
With conn
If .State = adStateClosed Then
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "/addresslist.mdb" & _
";Persist Security Info=False"
.Open
End If
End With
End Sub

Public Function OpenRecordset(ByVal strSql As String) As ADODB.Recordset
Dim rs As New ADODB.Recordset
With rs
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Open strSql, conn, , , adCmdText
End With
Set OpenRecordset = rs
End Function

Public Function RunTrans(ByVal tranSql As String)
With conn
.BeginTrans
.Execute tranSql
.CommitTrans
End With
End Fun