Private Sub Form_Load()
Me.UserName.SetFocus
Me.UserName = "11111"
Me.PassWord = "20070604"
End Sub
Private Sub 登录_Click()
On Error GoTo Err_登录_Click Dim rs As New ADODB.Recordset Dim str As String
Dim num As Integer
str = "select COUNT(Person.ID) from Person where Person.ID='" & Me.UserName
str = str & "'and Person .PassaWord='" & Me.PassWord & "'"
Set rs = GetRS(str)
num = rs(0)
If IsNull(Me.UserName) Then
MsgBox ("请输入用户名!!!")
ElseIf IsNull(Me.PassWord) Then
MsgBox ("请输入用户密码!!!")
ElseIf num <> 1 Then
MsgBox ("无此用户,或者密码错误!!!")
Else
Me.Visible = False
DoCmd.OpenForm "主窗体"
End If
exit_登录_Click:
Exit Sub
End Sub
登录窗体代码 调试时显示 黑体字段出错 显示用户定义类型未定义 初学者 不太懂 请高手看看 谢谢
作者: roych 时间: 2011-4-14 08:52
1、请留意有没有引用ADO组件。
2、这个字符串有误:str = str & "'and Person .PassaWord='" & Me.PassWord & "'"
应该在and 前面再加上一个空格。
3、Set rs = GetRS(str)应为自定义函数,由于没有附件,暂不调试。按俺的估计,应该是:
dim rs as new adobd.recordset
rs.open str,currentproject.connection,3,1作者: zyp 时间: 2011-4-14 09:02
这样试试:
Private Sub 登录_Click()
If Me.UserName = "" Or IsNull(Me.UserName) Then
MsgBox "请输入用户名!!!"
Me.UserName.SetFocus
ElseIf Me.Password = "" Or IsNull(Me.Password) Then
MsgBox "请输入用户密码!!!"
Me.Password.SetFocus
Else
If IsNull(DLookup("[id]", "person", "[id]='" & Trim(Me.UserName) & "' AND [passWord]='" & Trim(Me.Password) & "'")) Then
MsgBox "无此用户,或者密码错误!!!", vbCritical
Else
Me.Visible = False
DoCmd.OpenForm "主窗体"
End If
End If
End Sub作者: zyp 时间: 2011-4-14 09:04
还有, 字段命名最好不要用"password"这类ACCESS的关键字或内建变量, 有时会出错的, 窗体的控件名也是作者: powerhao 时间: 2011-4-14 11:22 回复 zyp 的帖子
有没有将password字段和窗体上的password文本框 这两个都改一下名称试试作者: gxy1000 时间: 2011-4-14 18:25
Private Sub Command9_Click()
'定义 connection 对象
Dim cn As ADODB.Connection
'定义 recordset 对象
Dim Rs As New ADODB.Recordset
Dim username As String
Dim userpass As String
Dim sql As String
'使用access内置 connection对象
Set cn = CurrentProject.Connection
Text1.SetFocus
username = Text1.Text
Text3.SetFocus
userpass = Text3.Value
sql = "select*from 用户表 where 用户名 ='" & username & " 'and 密码 = '" & userpass & "'"
Debug.Print sql
Rs.Open sql, cn
If Rs.EOF Then
MsgBox "登录失败!再来"
Text1.SetFocus
Text1.Text = ""
Text3.SetFocus
Text3.Text = ""
Else
DoCmd.Close
DoCmd.OpenForm "主界面"
MsgBox "我靠!登录成功"
End If
'关闭 recodset 对象和connection对象并释放内存资源
Rs.Close
cn.Close
Set Rs = Nothing
End Sub