简体   繁体   English

MS Access VBA:如果登录失败,请返回登录表单

[英]MS Access VBA: Return to login form if login fails

I'm working on a login form using MS Access 2010 and VBA. 我正在使用MS Access 2010和VBA处理登录表单。 I have been able to create a message that pops up if a user enters a user/password combination that fails when those credentials are passed to a function that tries to log in to an ODBC database connection. 我能够创建一条消息,如果用户输入的用户名/密码组合失败,这些凭据传递给试图登录到ODBC数据库连接的函数时,该消息将弹出。 The login form then closes. 然后关闭登录表单。

What I would like to do is have the application return the focus to the login form and ask the user to try the login again. 我想做的是让应用程序将焦点返回到登录表单,并要求用户再次尝试登录。 Below is the current login error I have adapted from the info at this URL: http://allenbrowne.com/ser-23a.html 以下是我已根据此URL上的信息改编的当前登录错误: http : //allenbrowne.com/ser-23a.html

ErrorHandler:
    strMsg = "An unexpected situation arose in your program." & vbCrLf & _
        "Please write down the following details:" & vbCrLf & vbCrLf & _
        "Unable to sign in because of Error: " & Err.Number & vbCrLf &     Err.Description
    MsgBox strMsg, vbCritical
    Exit Function

Does anyone have a hint or reference on how to get that behavior using VBA? 有没有人暗示或参考过如何使用VBA获得这种行为?

Thanks for any help, jrdevdba 感谢您的帮助,jrdevdba

After "msgBox strMsg, vbCritical" in your error handler add the following: 在错误处理程序中的“ msgBox strMsg,vbCritical”之后,添加以下内容:

DoCmd.OpenForm "LoginFormName"

Then in the Form_Open event of the login form put 然后在登录表单的Form_Open事件中

me.TextBoxName.SetFocus

You'll need to change "LoginFormName" and "TextBoxName" to the name of your forms. 您需要将“ LoginFormName”和“ TextBoxName”更改为表单的名称。 I'd be curious as to why the login form is closing but I'd need to see the rest of your code for that. 我很好奇为什么关闭登录表单,但是我需要查看其余的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM