我今天来找你,就一个我仍有问题的编码提出一些建议。它一开始就处于正常状态,但后来我决定将其调整到实际情况,以便将其分析基于子表单元素。
你介意看看它并说出错了吗?
非常感谢你的帮助:
Public Function Resetpassword()
'On Error GoTo Macro1_Err
Dim frm As Form
Set frm = Screen.ActiveForm
If DLookup("[User login]![Password]", "[User login]", "[User login]![Username]= [Textlogin]") = frm.Forms.navigationsubform.Textpass.Value Then
If frm.Forms.navigationsubform.Textnewpass.Value = frm.Forms.navigationsubform.Textnewpassconfirmation.Value Then
strsql = "UPDATE [User login]" _
& "SET [User login].[Password] =" & frm.Forms.navigationsubform.[Textnewpass].Value _
& "WHERE ((([User login].[Username])=" & frm.Forms.navigationsubform.[Textlogin].Value & "));"
DoCmd.RunSQL strsql
Beep
MsgBox "Your password has been effective. Thanks!", vbOKOnly, "Success"
Exit Function
Else
Beep
MsgBox "You must confirm you new password.", vbOKOnly, ""
End If
Else
Beep
MsgBox "You might have enter an invalid password, please retry.", vbOKOnly, ""
End If
'Macro1_Exit:
'Exit Function
'Macro1_Err:
'MsgBox Error$
'Resume Macro1_Exit
End Function
我收到2465错误:'应用程序定义或对象定义错误"
致以最诚挚的问候,
答案 0 :(得分:0)
我终于找到了答案。我在这里发布它,以防其他一些人遇到同样的问题。
我的代码无效,因为它没有考虑到他在子表单中的事实。
最终工作代码:
'------------------------------------------------------------
' Reset Password
'
'------------------------------------------------------------
Public Function Resetpassword()
'On Error GoTo Macro1_Err
Dim frm As Form
Set frm = Screen.ActiveForm
If DLookup("[Password]", "[User login]", "[Username]='" & frm.navigationsubform.Form![Textlogin].Value & "'") = frm.navigationsubform.Form!Textpass.Value Then
If frm.navigationsubform.Form!Textnewpass.Value = frm.navigationsubform.Form!Textnewpassconfirmation.Value Then
strsql = "UPDATE [User login]" _
& "SET [User login].[Password] ='" & frm.navigationsubform.Form![Textnewpass] _
& "' WHERE ((([User login].[Username])='" & frm.navigationsubform.Form![Textlogin] & "'));"
DoCmd.RunSQL strsql
Beep
MsgBox "Your password has been effective. Thanks!", vbOKOnly, "Success"
Exit Function
Else
Beep
MsgBox "You must confirm you new password.", vbOKOnly, ""
End If
Else
Beep
MsgBox "You might have enter an invalid password, please retry.", vbOKOnly, ""
End If
'Macro1_Exit:
'Exit Function
'Macro1_Err:
'MsgBox Error$
'Resume Macro1_Exit
End Function
此致