求助啊~~~~`~~~~

okcat 2004-09-06 09:50:01
Dim st As String
Dim rs As ADODB.Recordset
Dim con As ADODB.Connection

Private Sub Command1_Click()
If Text1.Text = "" And Text2.Text <> "" Then
MsgBox "请输入用户名"
Text1.SetFocus
Exit Sub
ElseIf Text2.Text = "" And Text1.Text <> "" Then
MsgBox "请输入密码"
Text2.SetFocus
Exit Sub
ElseIf Text1.Text = "" And Text2.Text = "" Then
MsgBox "请输入用户名与密码"
ElseIf Text1.Text <> "" And Text2.Text <> "" Then
Set con = New ADODB.Connection
st = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\桌面\新建 Microsoft Office Access 应用程序.mdb;Persist Security Info=False"
con.Open st
rs.Open "select * from 表1", con
rs.Find "用户名='" & Trim(Text1.Text) & "'"
If rs.EOF = True Then
MsgBox "输入的用户名不存在,请重新输入"
Text1.SetFocus
Exit Sub
End If
rs.Find "密码='" & Trim(Text2.Text) & "'"
If rs.EOF = True Then
MsgBox "输入的密码不正确,请重新输入"
Text2.SetFocus
Exit Sub
End If
Form2.Show
End If
End Sub



rs.Open "select * from 表1", con  提示出错,对象变量或With块变量未定义。这又是哪里不对啊,我快晕了


...全文
47 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wumylove1234 2004-09-07
正解
回复
befree 2004-09-07
new 一个
回复
zhangzumiao 2004-09-07
你少定义了变量或你少了控件
回复
羽毛之家 2004-09-07
set rs=new adodb.recordset
来晚了,但愿能分到分啊
回复
of123 2004-09-07
......
Set rs = New ADODB.Recordset
rs.Open "select * from 表1 Where 用户名='" & Trim(Text1.Text) & "'", con
If rs.EOF Then
MsgBox "输入的用户名不存在,请重新输入"
Text1.SetFocus
Exit Sub
End If
If rs.!密码 <> Trim(Text2.Text) Then
MsgBox "输入的密码不正确,请重新输入"
Text2.SetFocus
Exit Sub
End If
rs.Close
回复
david1981 2004-09-07
像这类错误一般是没有对对象进行实例话而导致的,正如楼上所说,在使用cn和rs这两个对象变量之前,你必须对他们进行后期实例化。如:
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
或者在声明对象变量之时就对对象进行前期的实例化,如:
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
回复
RUKYO 2004-09-07
在定义时最好这样写:
Dim rs As New ADODB.Recordset
Dim con As New ADODB.Connection
回复
xiaohuasz 2004-09-06
Set rs = New ADODB.Recordset '先要实例化
回复
相关推荐
发帖

1187

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2004-09-06 09:50
社区公告
暂无公告