Public Function OpenRS(strSql As String, rs As ADODB.Recordset)
Set rs = New ADODB.Recordset
rs.Open strSql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
End Function
Public Sub Execute(strSql As String)
DoCmd.RunSQL strSql
End Sub
Private Sub cmdenter_Click()
Dim strusername, strpassword As String
Dim flag As Integer
Dim rs As ADODB.Recordset
flag = 0
'从“用户”表里读取用户名和密码
OpenRS ("SELECT * FROM User_account"), rs
'循环判断用户名是否存在,密码是否正确
Do Until rs.EOF
strusername = rs("User_name")
strpassword = rs("Password")
If UCase(Me.txtusername.Value) <> UCase(strusername) Then
rs.MoveNext
'若相等,说明用户名存在,可以跳出循环
Else
flag = 1
Exit Do
End If
Loop
'flag=0 说明用户名不存在,进行处理
'设置文本框的内容为空,“确定”键不可用,焦点设在txtusername
If flag = 0 Then
MsgBox "没有这个用户名,请重新输入"
Me.txtpassword.Value = ""
Me.txtusername.Value = ""
Me.txtusername.SetFocus
cmdenter.Enabled = False
Exit Sub
'若flag=1 说明所输入的用户名存在,进一步比较密码是否正确
'若密码出错,设置txtusername的内容不变,txtpassword的内容为空,
'若密码出错,“确定”键不可用,并把焦点设在txtpassword
Else
If UCase(Me.txtpassword.Value) <> UCase(strpassword) Then
MsgBox "密码错误,请重新输入"
Me.txtpassword.Value = ""
Me.txtpassword.SetFocus
cmdenter.Enabled = False
Exit Sub
End If
End If
'用户名和密码都正确,打开“主界面”窗体
DoCmd.Close
DoCmd.OpenForm "Order_form_temp"
End Sub作者: Henry D. Sy 时间: 2009-3-24 06:21
引用ado试试作者: ACMAIN_CHM 时间: 2009-3-24 07:59
当将最前面的一部分程式码拿走后, 可以打开Login表单, 但也发生错误
拿走的程式码:
Public Function OpenRS(strSql As String, rs As ADODB.Recordset)
Set rs = New ADODB.Recordset
rs.Open strSql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
End Function
Public Sub Execute(strSql As String)
DoCmd.RunSQL strSql
End Sub
错误信息如下:
但是当小弟将后段程式码(由Private Sub cmdenter_Click() ...开始)
中的一部分换成这样后, 程式码正常发挥作用
Private Sub cmdenter_Click()
Dim strusername, strpassword As String
Dim flag As Integer
Dim rs As Dao.Recordset
'从“用户”表里读取用户名和密码
Set rs = CurrentDb.OpenRecordset("User_account")
flag = 0
'循环判断用户名是否存在,密码是否正确
Do Until rs.EOF
...