类型不匹配错误我不知道该怎么做

时间:2016-09-28 15:32:17

标签: ms-access access-vba

我一直收到类型不匹配的错误,我不确定我做错了什么。

这是我到目前为止所尝试的:

Private Sub Command1_Click()
Dim UserLevel As Integer

If IsNull(Me.txtLoginID) Then
    MsgBox "Please Enter Login ID", vbInformation, "Login ID Required"
    Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please Enter Password", vbInformation, "Password Required"
    Me.txtPassword.SetFocus
Else
    If (IsNull(DLookup("UserLogin", "Accounts", "UserLogin='" & Me.txtLoginID.Value & "'"))) Or _
    (IsNull(DLookup("Password", "Accounts", "Password='" & Me.txtPassword.Value & "'"))) Then
        MsgBox "Incorrect Login ID or Password"
    Else
        UserLevel = DLookup("UserSecurity", "Accounts", "UserLogin= '" & Me.txtLoginID.Value & "'")
        DoCmd.Close
            If UserLevel = admin Then
        DoCmd.OpenForm "Administrator"
    Else
         DoCmd.OpenForm "Sales"
        End If
    End If
End If

1 个答案:

答案 0 :(得分:0)

尝试用Nz替换你的IsNull:

 If Nz(DLookup("UserLogin", "Accounts", "UserLogin='" & Me.txtLoginID.Value & "'")) Or _
Nz(DLookup("Password", "Accounts", "Password='" & Me.txtPassword.Value & "'")) Then
    MsgBox "Incorrect Login ID or Password"