主题:连接数据库提示变量未定义咋回事呢?
Option Explicit
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
'打开数据库连接
Public Sub OpenConn()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Data.eq;Jet OLEDB:Database Password=cjw79512;Persist Security Info=False;"
End Sub
'关闭数据库连接
Public Sub CloseConn()
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
我一调试就提示变量会定义,代码应该没有问题,是哪里错了呢?请大虾们指点一下
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
'打开数据库连接
Public Sub OpenConn()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Data.eq;Jet OLEDB:Database Password=cjw79512;Persist Security Info=False;"
End Sub
'关闭数据库连接
Public Sub CloseConn()
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
我一调试就提示变量会定义,代码应该没有问题,是哪里错了呢?请大虾们指点一下