Creating Access cmdButton to Compare Data with VBScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kadumel
    New Member
    • Oct 2008
    • 1

    Creating Access cmdButton to Compare Data with VBScript

    I pose a question as a newbie here -

    I have been trying to do the following : I created a form that is set to start-up first. I know that microsoft security is better for security and I won't be using it anyway. I have the person type into 2 list boxes their username and password, and then want it to compare to a table named UserList. I have tried a couple different ways to compare the data, but the way I think I should do it is as such.

    Code:
    Private Sub cmdLogin2_Click()
    On Error GoTo Err_cmdLogin2_Click
    
        Dim stUserName1, stusername2, stpassword1, stPassword2, As String
    
        
        Set stUserName1 = me.lstUserID
        Set stusername2 = me.lstPassword
        Set stpassword1 = tables.userlist("Password")
        Set stPassword2 = tables.userenter("Password")
            
        IIf ((stUserName1 = stusername2) = True), (Open Form "Sample"), (MsgBox("Incorrect UserName or Password!", Open Form "Login")
    
    Exit_cmdLogin2_Click:
        Exit Sub
    
    Err_cmdLogin2_Click:
        MsgBox Err.Description
        Resume Exit_cmdLogin2_Click
        
    End Sub
    I know there are many errors in that code and some of it I just type in right now to get the idea of what I am trying to do. Any help would be appreciated!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32668

    #2
    Check out this recent thread (Restrict multiple logins with single username at sametime in ms access). It should help you.

    Welcome to Bytes!

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      No matter how you implement your logic, Passwords should always be an 'exact' match (case sensitive), as least in my humble opinion. One way to check for an exact match is with the StrComp() Function. I'll post a simple example below for you to review:
      Code:
      Dim strOne As String
      Dim strTwo As String
      Const conEXACT_MATCH As Byte = 0
      
      strOne = "Antelope"
      strTwo = "antelope"
      
      If StrComp(strOne, strTwo, vbBinaryCompare) = conEXACT_MATCH Then
        Debug.Print "Exact Match!"
      Else
        Debug.Print "Not an Exact Match!"
      End If
      OUTPUT
      Code:
      Not an Exact Match!

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32668

        #4
        In my opinion too. And I'm never humble :D

        Comment

        Working...