实时错误91,“对象变量或with变量未设置”是怎么回事?
模块:
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Sub main()
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\personinfo.mdb;Persist Security Info=False"
cn.Open '打开连接
Set rs = New ADODB.Recordset
frmdl.Show
End Sub
登录窗体
Private Sub Command1_Click()
rs.Open "select * from user_tbl where u_name='" & Combo2.Text & "'", cn, adOpenStatic, adLockReadOnly
If rs.RecordCount > 0 Then
If Text1(1).Text = rs.Fields("u_password").Value Then
Unload Me
frmgr.Show
MDIForm1.Show
Else
MsgBox "用户名或密码错误!", vbInformation, "提示"
End If
End If
End Sub
请前辈指点!
[解决办法]
错误出在那一行?按F8单步调试一下
[解决办法]
http://download.csdn.net/source/1498324
[解决办法]
- VB code
'模块 codeOption Explicit Public cn As New ADODB.Connection Public rs As New ADODB.RecordsetSub main() cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\personinfo.mdb;Persist Security Info=False" cn.Open '打开连接 frmdl.ShowEnd Sub'登录窗体Option ExplicitPrivate Sub Command1_Click() sql = "select * from user_tbl where u_name='" & Combo2.Text & "'" rs.CursorLocation = adUseClient rs.Open sql, cn, adOpenDynamic, adLockOptimistic If rs.RecordCount > 0 Then If Text1(1).Text = rs.Fields("u_password").Value Then Unload Me frmgr.Show MDIForm1.Show Else MsgBox "用户名或密码错误!", vbInformation, "提示" End If End IfEnd Sub
[解决办法]
- VB code
'模块 codeOption Explicit Public cn As ADODB.Connection '定义数据库的连接存放数据和代码 Public rs As ADODB.Recordset Public sql As StringSub main() Set cn = New ADODB.Connection cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\personinfo.mdb;Persist Security Info=False" cn.Open '打开连接 Set rs = New ADODB.Recordset frmdl.ShowEnd Sub