DLookup 函数 - 返回错误值
DLookup Function - returning wrong value
我正在尝试 运行 以下代码,但我在 DLookUp 上收到 运行 时间错误“2471”。 "The expression you entered as a query parameter produced this error: 'dkim'"。
DLookUp returns 一个值,但它返回了错误的值。此代码应该将 Text7 与 dlookup 'Password' 值进行比较。我错过了什么吗?
Private Sub btn_enter_Click()
If Me.Text7.Value = DLookup("Password", "tbl_ref_users", _
"[ID]=" & Me.Text5.Value) Then
ID = Me.Text5.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "form_Login", acSaveNo
DoCmd.OpenForm "form_Menu"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.Text7.SetFocus
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
I'm getting a Run-time error '2471' on DLookUp. "The expression you
entered as a query parameter produced this error: 'dkim'".
由于DLookup
表达式是DLookup("Password", "tbl_ref_users", "[ID]=" & Me.Text5.Value)
,所以Me.Text5
的.Value
可能是dkim.
在那种情况下,引用 DLookup
条件中的文本框值:
DLookup("[Password]", "tbl_ref_users", "[ID]='" & Me.Text5.Value & "'")
但是 tbl_ref_users.ID
的数据类型必须是文本才能工作。如果它是数字,则需要将其与数字而不是文本字符串进行比较,例如 "dkim".
另请注意,我将字段名称 Password 括起来,因为它是保留字。
我正在尝试 运行 以下代码,但我在 DLookUp 上收到 运行 时间错误“2471”。 "The expression you entered as a query parameter produced this error: 'dkim'"。
DLookUp returns 一个值,但它返回了错误的值。此代码应该将 Text7 与 dlookup 'Password' 值进行比较。我错过了什么吗?
Private Sub btn_enter_Click()
If Me.Text7.Value = DLookup("Password", "tbl_ref_users", _
"[ID]=" & Me.Text5.Value) Then
ID = Me.Text5.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "form_Login", acSaveNo
DoCmd.OpenForm "form_Menu"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.Text7.SetFocus
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
I'm getting a Run-time error '2471' on DLookUp. "The expression you entered as a query parameter produced this error: 'dkim'".
由于DLookup
表达式是DLookup("Password", "tbl_ref_users", "[ID]=" & Me.Text5.Value)
,所以Me.Text5
的.Value
可能是dkim.
在那种情况下,引用 DLookup
条件中的文本框值:
DLookup("[Password]", "tbl_ref_users", "[ID]='" & Me.Text5.Value & "'")
但是 tbl_ref_users.ID
的数据类型必须是文本才能工作。如果它是数字,则需要将其与数字而不是文本字符串进行比较,例如 "dkim".
另请注意,我将字段名称 Password 括起来,因为它是保留字。