Ms access Microsoft Access编译错误:找不到方法或数据成员

Ms access Microsoft Access编译错误:找不到方法或数据成员,ms-access,vba,Ms Access,Vba,我正在为我的数据库创建一个简单的登录表单。单击“登录”时,会显示消息“编译错误:未找到方法或数据成员”。我该如何解决这个问题?谢谢代码如下 Option Compare Database Option Explicit Private Sub btnLogin_Click() Dim rs As Recordset Set rs = CurrentDb.OpenRecordset("TBL:Staff", dbOpenSnapshot, dbReadOnly) rs

我正在为我的数据库创建一个简单的登录表单。单击“登录”时,会显示消息“编译错误:未找到方法或数据成员”。我该如何解决这个问题?谢谢代码如下

Option Compare Database
Option Explicit

Private Sub btnLogin_Click()
    Dim rs As Recordset

    Set rs = CurrentDb.OpenRecordset("TBL:Staff", dbOpenSnapshot, dbReadOnly)

    rs.FindFirst "UserName='" & Me.txtUserName & "'"

    If rs.NoMatch = True Then
        Me.lblWrongUser.Visible = True
        Me.txtUserName.SetFocus
        Exit Sub
        Me.lblWrongUser.Visible = False

    If rs!Password <> Nz(Me.txtPassword, "") Then
        Me.lblWrongPass.Visible = True
        Me.txtPassword.SetFocus
        Exit Sub
    End If
    Me.lblWrongPass.Visible = False
    DoCmd.OpenForm "FRM:Customer"
    DoCmd.Close acForm, Me.Name
End Sub
选项比较数据库
选项显式
专用子btnLogin_单击()
将遥感器作为记录集
Set rs=CurrentDb.OpenRecordset(“TBL:Staff”、dbOpenSnapshot、dbReadOnly)
rs.FindFirst“UserName=”&Me.txtUserName&“
如果rs.NoMatch=True,则
Me.lblWrongUser.Visible=True
Me.txtUserName.SetFocus
出口接头
Me.lblWrongUser.Visible=False
如果是的话!密码Nz(Me.txtPassword,“”),然后
Me.lblWrongPass.Visible=真
Me.txtPassword.SetFocus
出口接头
如果结束
Me.lblWrongPass.Visible=False
DoCmd.OpenForm“FRM:客户”
DoCmd.Close acForm,Me.Name
端接头
试试这个

检查是否提供了用户名和密码值,然后通过简单的
DCount
查看它们是否存在于数据库中

如果用户名/密码存在,则返回>0;如果不存在,则返回0

Private Sub btnLogin_Click()
    With Me
        'Username/Password - value provided?
        If IsNull(.txtUserName.Value) Or IsNull(.txtPassword.Value) Then
            MsgBox "Both fields required.", vbExclamation
            Exit Sub
        End If

        'Username exists in Table?
        If DCount("*", "Staff", "UserName='" & .txtUserName.Value & "'") = 0 Then
            .lblWrongUser.Visible = True
            .txtUserName.SetFocus
            Exit Sub
        End If

        'Password exists in Table?
        If DCount("*", "Staff", "UserName='" & .txtUserName.Value & _
                                "' And Password='" & .txtPassword.Value & "'") = 0 Then
            .lblWrongPass.Visible = True
            .txtPassword.SetFocus
            Exit Sub
        End If
    End With

    'Code will reach here only if supplied username and passowrd are correct
    With DoCmd
        .OpenForm "Customer", acNormal, , , acFormPropertySettings, acWindowNormal
        .Close acForm, Me.Name, acSavePrompt
    End With
End Sub

请提供给出错误的行。第4行导致了错误。我认为Erik是指代码中的行。此外,如果缺少,这将不会编译为
结束。查看缩进,在行
Me.lblWrongUser.Visible=False
之后,这一行将永远不会执行,因为它前面有一个
Exit Sub