access窗体登陆问题

来源:百度知道 编辑:UC知道 时间:2024/05/19 01:02:15
有两个窗体,fr1,fr2
按钮command4
text0,text2为用户名和密码的文本框
用户不存在和出错时都正确
但正确时会出错误424,要求对象
怎么修改
thx~
Private Sub Command4_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim connstr As String
connstr = "provider=microsoft.jet.oledb.4.0;data source=db1.mdb"
sql = "select * from tb_id where id='" & Text0 & "'"
conn.Open (connstr)
rs.Open sql, conn, 1, 1
If rs.RecordCount = 0 Then
MsgBox "用户不存在"
rs.Close
conn.Close
Exit Sub
End If
If Text2 <> rs("pwd") Then
MsgBox "用户口令错误"
rs.Close
conn.Close
Else
rs.Close
conn.Close
fr2.show
Unload Me
End If

End Sub

你这样试一下:
Private Sub Command4_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim connstr As String
Dim text0=val(Text0.Text)//用于获取用户名输入框内的值
Dim text2=val(Text2.Text)//用于获取密码
connstr = "provider=microsoft.jet.oledb.4.0;data source=db1.mdb"
sql = "select top 1 * from tb_id where id='" & text0 & "'"//改这里的变量
conn.Open (connstr)
rs.Open sql, conn, 1, 1
If rs.RecordCount = 0 Then
MsgBox "用户不存在"
rs.Close
conn.Close
Exit Sub
End If

If text2 <> rs("pwd") Then//改这里的变量
MsgBox "用户口令错误"
rs.Close
conn.Close
Else
rs.Close
conn.Close
fr2.show
Unload Me
End If

End Sub

检查一下fr2 窗体存不存在,名字是否正确

要求对象,那就是你的对象名字有错误!
仔细检查一下!