Vba MS Access密码掩码和查询
我有一个简单的表单,需要用户名和密码。然后,它检查数据库以确认用户存在并且密码正确。如果是这样,它只会打开另一个表单。问题是,当密码字段使用密码标记时,查询会尝试按字面上的星号匹配Vba MS Access密码掩码和查询,vba,ms-access,Vba,Ms Access,我有一个简单的表单,需要用户名和密码。然后,它检查数据库以确认用户存在并且密码正确。如果是这样,它只会打开另一个表单。问题是,当密码字段使用密码标记时,查询会尝试按字面上的星号匹配 Private Sub cmdAccept_Click() ' Create entry points for the database and the query... Dim rd As dao.Recordset Dim sql As String ' Define the query to be perfo
Private Sub cmdAccept_Click()
' Create entry points for the database and the query...
Dim rd As dao.Recordset
Dim sql As String
' Define the query to be performed...
sql = "SELECT [_User], [_Password] FROM tblEmployees WHERE [_User] = '" + frmUser + "'"
' The user pressed the key to log in...
' Check that User and Password aren't empty...
If Len(Me.txtUser) > 0 Then
' There is something in the field...
' MsgBox ("There is something in the User field...")
Me.txtUser.SetFocus
frmUser = Trim(Me.txtUser.Text)
frmBoolUser = True
Else
' Nothing to see here...
MsgBox ("You need to enter your user name...")
frmBoolUser = False
End If
If Len(Me.txtPassword) > 0 Then
' There is something in the field...
' Msgbox ("There is something in the Password field...")
Me.txtPassword.SetFocus
frmPassword = Trim(Me.txtPassword.Text)
frmBoolPassword = True
Else
' Nothing to see here...
MsgBox ("You need to enter your password...")
frmBoolPassword = False
End If
If (frmBoolUser And frmBoolPassword) Then
' Both fields have data on them...
'MsgBox ("The credentials for " + frmUser + " with the password " + frmPassword + " are about to be checked...")
' MsgBox (sql)
Set rs = CurrentDb.OpenRecordset(sql)
If rs.EOF Then
' We didn't find such user name...
MsgBox ("No records...")
Else
MsgBox ("Yup, the user name exists!")
' Thus, we need to check if the provided password is the correct one...
' MsgBox (frmPassword)
' MsgBox (rs.[_Password])
If (rs.[_Password]) = (frmPassword) Then
' The password is correct...
' MsgBox ("You're awesome!")
DoCmd.OpenForm "frmMenu"
Else
' The password is incorrect...'
MsgBox ("Well, that didn't work, did it?")
End If
End If
End If
端接头
所以问题就在这里:
如果(rs.[U密码]=(frmPassword),则
密码是12345。因此,frmPassword包含******,这与字段密码包含的内容不同,字段密码是12345
这里我肯定遗漏了一些东西,因为在系统中无法读取密码掩码是荒谬的
任何帮助都将不胜感激 我想补充一点,只要您不在密码字段中使用密码掩码,代码就可以正常工作。不要使用
.Text
,使用.Value
。@Andre的注释就是答案。是的。Andre answer解决了这个问题。非常感谢。