首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenForm被取消了,错误再次发生。

OpenForm被取消了,错误再次发生。
EN

Stack Overflow用户
提问于 2017-05-03 06:33:42
回答 1查看 84关注 0票数 0

OpenForm已在我的应用程序中重新发生。我拆了两次车,修理了两次。

代码抛出错误:“打开菜单表单DoCmd.OpenForm”,acNormal,,,acWindowNormal

当我第一次遇到这个错误时,我通过更改来解决它:

代码语言:javascript
复制
DoCmd.OpenForm "Menu", acNormal, "", "", , acNormal

代码语言:javascript
复制
DoCmd.OpenForm "Menu", acNormal, , , , acWindowNormal.

这是我的程序,遭受例外:

代码语言:javascript
复制
Private Sub Login(recordSet As DAO.recordSet, PERSAL As String, Password As String)
On Error GoTo Login_ErrHandler

'Check to see if the recordset actually contains rows
If Not (recordSet.EOF And recordSet.BOF) Then
    recordSet.MoveFirst 'Unnecessary in this case, but still a good habit

    'See if credentials match data
    Do
        If (recordSet!User_ID = PERSAL And recordSet!Password = Password) Then

           'Open Menu form
            DoCmd.OpenForm "Menu"
           ' Form_Menu.op

            recordSet.Close 'Close the recordset
            Set recordSet = Nothing 'Clean up

            'Close Login form
            DoCmd.Close acForm, "Login"

            Exit Do
        End If

        recordSet.MoveNext

        If (recordSet.EOF Or recordSet.BOF) Then
            MsgBox "Your credentials are incorrect or you are not registered."

            Exit Do
        End If
    Loop

    'Match the values entered for PERSAL nr. and password fields with a row in User table

Else

    MsgBox "There are no records in the recordset."

     recordSet.Close 'Close the recordset
     Set recordSet = Nothing 'Clean up

End If

Form_Login.txtUser_ID.SetFocus

Login_ErrHandler:
If Err = 2501 Then
    'MsgBox "No data to display"
    DoCmd.Hourglass False
    Resume Login_ErrHandler
' Else

 '   MsgBox Err.Description, vbCritical
End If

End Sub

这一次我如何修复这个错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-03 20:55:54

使用以下SQL创建参数化查询:

代码语言:javascript
复制
PARAMETERS [prmUserId] Text ( 255 ), [prmPassword] Text ( 255 );
SELECT User_ID, Password 
FROM YOUR_TABLE_NAME
WHERE ((([User_ID])=[prmUserId]) AND (([Password])=[prmPassword]));

假设代码在Login表单后面:

代码语言:javascript
复制
Private Sub Login(ByVal PERSAL As String, ByVal Password As String)
    On Error GoTo Login_ErrHandler

    Dim qdf As DAO.QueryDef
    Set qdf = CurrentDb().QueryDefs("YourQueryName") 'Change to your query name
        qdf.Parameters("[prmUserId]").Value = PERSAL
        qdf.Parameters("[prmPassword]").Value = Password

    Dim rs As DAO.recordSet
    Set rs = qdf.OpenRecordset()

    'No records
    If rs.EOF Then
        MsgBox "Your credentials are incorrect or you are not registered."
        Me.txtUser_ID.SetFocus
        GoTo Leave
    End If

    'User found

    'Close Login Form
    DoCmd.Close acForm, Me.Name, acSavePrompt

    'Open Form
    DoCmd.OpenForm "Menu", acNormal, , , acFormPropertySettings, acWindowNormal

Leave:
    On Error Resume Next
        rs.Close
    Set rs = Nothing
        qdf.Close
    Set qdf = Nothing
    On Error GoTo 0
    Exit Sub

Login_ErrHandler:
    MsgBox Err.Number & " - " & Err.Description, vbCritical
    Resume Leave
End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43752716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档