Select statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erniemack
    New Member
    • Mar 2010
    • 10

    Select statement

    Ok I am an old time programmer but I can not understand why I get a compile error on the following statement. I am using access 2003

    SELECT tblUser.User FROM tblUser

    I have a form where I want the user to type an ID and Password then upon exiting the password I want to check a table to be sure the combination is there and also assign a level of security based upon a third field in the table. The table contains:
    User
    Password
    Level

    Thanks
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    This is simply a SELECT Statement that will return all Values in the [User] Field in tblUser, nothing more.

    Comment

    • erniemack
      New Member
      • Mar 2010
      • 10

      #3
      This I know. Why will it not compile and how would I code a lookup to check a user name and password. To my old timer way of thinking you would have the user key in an id and password then look up that user's record in a table and check to see if the typed password matches the one in the table. You would then be able to use other info in the table to determine what access to give this user.
      Thanks

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        1. Assumptions:
          1. Table Name is tblLogins, and consists of Fields [UserID] {TEXT} and [Password] {TEXT}
          2. Field Name on Form to accept UserID is txtUserID
          3. Field Name on Form to accept Password is txtPassword
          4. Case Sensitive comparison on Password, namely: Password <> PassworD
        2. Code definition:
          Code:
          Dim strPassWord As String
          Dim txtUsr As TextBox
          Dim txtPWrd As TextBox
          
          Set txtUsr = Me![txtUserID]
          Set txtPWrd = Me![txtPassword]
          
          'Make sure there is something entered in each Text Box
          If IsNull(txtUsr) Or IsNull(txtPWrd) Then Exit Sub
          
          'Mask the Password
          txtPWrd.InputMask = "Password"
          
          'First, check for a Valid UserID, the one entered by the User
          If DLookup("[UserID]", "tblLogins", "[UserID] = '" & txtUsr & "'") <> "" Then
            strPassWord = DLookup("[Password]", "tblLogins", "[UserID] = '" & txtUsr & "'")
              'UserID OK, but must now perform a 'Case-Sensitive' comparison on the Password
              If StrComp(strPassWord, txtPWrd, vbBinaryCompare) = 0 Then
                'ALL is OK, User ID and Password match exactly, proceed
                MsgBox "Valid UserID/Password combination!"
              Else
                MsgBox txtPWrd & " is not a Valid Password", vbExclamation, "Password Not Found"
              End If
          Else
            MsgBox txtUsr & " is an Invalid User ID", vbExclamation, "User ID Not Found"
          End If

        Comment

        • erniemack
          New Member
          • Mar 2010
          • 10

          #5
          Thanks very much. It is hard for me to wrap myself around some of this code when I try it myself. I understand what you sent tho. I have been programming since 1965 using basic, NCR Neat/3 and a db language that you have probably never heard of TAS. Some of the pictures are coming into focus thanks to people like you!

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by erniemack
            Thanks very much. It is hard for me to wrap myself around some of this code when I try it myself. I understand what you sent tho. I have been programming since 1965 using basic, NCR Neat/3 and a db language that you have probably never heard of TAS. Some of the pictures are coming into focus thanks to people like you!
            Glad to be of service to you. Programming is like ridding a bicycle - once you get back on, it's like you never forgot! (LOL)

            Comment

            Working...