Results 1 to 4 of 4
  1. #1
    Join Date
    May 2014
    Posts
    98

    Unanswered: code not working

    I don't know what I am doing wrong when I login as user Y= 3 then it gives me error 2467. "the expression you entered refers to an object that is closed or does not exist."
    and take me to the code line highlighted below.
    I think it's confusing Y for 1, 2 and 3 as if I comment 1 and 2 code then 3 works fine and vice versa.

    Code:
    Private Sub Command10_Click()
    If IsNull(txtUsername) Then
            MsgBox "Invalid Username"
            Exit Sub
    End If
        If IsNull(txtPassword) Then
            MsgBox "Invalid Password"
            Exit Sub
    End If
    
    Dim X As Long
    X = Nz(DLookup("UserID", "UserT", "Username='" & txtUsername & "' AND Password='" & txtPassword & "'"))
    
    If X > 0 Then
     Dim Y As Long
        Y = Nz(DLookup("GroupID", "GroupXUserT", "UserID='" & X & "'"))
        
        'MsgBox "" & Y & ""
        'We have a valid user
        If Y = 1 Or 2 Then
            DoCmd.OpenForm "MainMenu"
            Forms!MainMenu!txtUserID = X
            LogIt X, "User Logon"
            Forms!MainMenu!txtUsername = txtUsername
            DoCmd.Close acForm, "LoginF"
        End If
    
    Else
        MsgBox "Invalid Logon"
    End If
    
    If Y = 3 Then
            DoCmd.OpenForm "MainMenu"
            Forms!MainMenu!txtUserID = X
            LogIt X, "User Logon"
           Forms!MainMenu!txtUsername = txtUsername
           DoCmd.Close acForm, "LoginF"
            Forms!MainMenu!Command27.Visible = False
        End If

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what datatype is X?
    string values must be delimted by a pair of ' or "
    dates (ISO [yyyy/mm/dd] or US format [mm/dd/yyyy]) delimited by #
    numeric values as is
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    May 2014
    Posts
    98
    Thanks Healdem
    It was numeric I was using extra "or"
    Quote Originally Posted by healdem View Post
    what datatype is X?
    string values must be delimted by a pair of ' or "
    dates (ISO [yyyy/mm/dd] or US format [mm/dd/yyyy]) delimited by #
    numeric values as is
    Code:
    If Y = 1 Or 2 Then

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    It should be:
    Code:
    If Y = 1 Or Y = 2 Then
    Otherwise it actually means:
    Code:
    If Y = True
    This is because 1 Or 2 <> 0 (True).
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •