Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Location
    Inverurie
    Posts
    628

    Unanswered: What am i doing wrong?

    I am trying to make a login form for a database, but im having a few problems.

    here's the code for it:

    Code:
    Private Sub login_button_Click()
    'Check to see if a username is selected
    If IsNull(Me.login_select) Or Me.login_select = "" Then
    DoCmd.Close
    DoCmd.OpenForm "error1"
    Exit Sub
    End If
    
    'Check to see if data is entered into the password box
    If IsNull(Me.password) Or Me.password = "" Then
    DoCmd.Close
    DoCmd.OpenForm "error2"
    Exit Sub
    End If
    
    'Check to see if the password entered matches
    'the password in the Employees table.
    
    If Me.password.Value = DLookup("Password", "Employees", "[EmployeeID]=" & Me.login_select.Value) Then
    
    MyEmployeeID = Me.login_select.Value
    
    'Close logon form and open splash screen
    DoCmd.Close acForm, "test_login", acSaveNo
    DoCmd.OpenForm "main"
    Else
    DoCmd.Close
    DoCmd.OpenForm "error2"
    End If
    End Sub
    The part im having problems with is the check password line. Im not sure that i have coded it correctly because every time i click on the login button, i just get the error message that i have set it to display.

    can anyone give me some advice on how to rectify this problem?

  2. #2
    Join Date
    Sep 2004
    Posts
    10
    Maybe you can do the SQL first, something like this:
    SELECT password
    FROM employes
    WHERE ...............

    to do it in the code you put:
    SQL=" " 'the sql statment like a string
    Set db = CurrentDb()
    Set Recordset = db.OpenRecordset(SQL)
    Do Until Recordset.EOF
    if var=password.value then.... end if
    Recordset.MoveNext
    loop
    I hope you understand what I want to say

  3. #3
    Join Date
    Jul 2004
    Location
    Inverurie
    Posts
    628
    i think i can see where you're heading with it.

    something like:

    SELECT password
    FROM Employees
    WHERE password = (password field value on form)

    or:

    SQL="SELECT Employees.Password _
    FROM Employees _
    WHERE (((Employees.Password)=[Forms]![test_login]![password]));"
    Set db = CurrentDb()
    Set Recordset = db.OpenRecordset(SQL)
    Do Until Recordset.EOF
    if var=password.value then.... end if
    Recordset.MoveNext
    loop

  4. #4
    Join Date
    Nov 2003
    Posts
    11
    Mabe i'm not understanding the question.
    But couldn't you make the forms record source equal the table where the username and passwords are. Create a drop down box with the usenames which populates the form with all the user's data when a username is selected. Set the Users password box and everything else's visible property to false then replace your check line with:

    if [me].[typedpassword]=[me].[userspassword] then
    'insert login success code
    end if

    hope this helps

    Sudney

Posting Permissions

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