Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Nashaath is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10

    Help Needed in Login Form Codes


    I want to create a login screen where different users are directed to different forms on successful login. The code I wrote does not open any from on successful login. I am new to access, I need help in solving this problem. Thank you in advance.
    Here is the code

    Code:
     
    Option Compare Database
    Private intLogAttempt As Integer
    Private Sub cboUser_GotFocus()
    cboUser.Dropdown
    End Sub
    Private Sub close_form_click()
        Response = MsgBox("Do you want to close this application?", vbYesNo + vbQuestion, "Quit Application")
        
        If Response = vbYes Then
        Application.Quit
        End If
    End Sub
    
    Private Sub cmdOK_Click()
    Call Login
    End Sub
    
    Public Sub frm_load()
    txtFocus.SetFocus
    End Sub
    
    Public Sub Login()
    On Error GoTo ErrorHandler:
    
    If IsNull([cboUser]) = True Then
    MsgBox "Username is required"
    
    ElseIf IsNull([Password]) = True Then
    MsgBox "Password is required"
    
    Else
    
    If Me.Password.Value = DLookup("Password", "user", "[UserID]='" & Me.cboUser.Value & "'") Then
    
    strUser = Me.cboUser.Value
    strRole = DLookup("access_level", "user", "[UserID]'" & Me.cboUser.Value & "'")
    DoCmd.Close acForm, "frmLogin", acSaveNo
    MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome"
    DoCmd.OpenForm "admin_menu", acNormal, "", "", , acNormal
    
    Else
    MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password"
    intoLogAttempt = intLogAttempt + 1
    Password.SetFocus
    
    End If
    End If
    
    If intLogAttempt = 3 Then
    MsgBox "You do not have access to this database.Please contact admin." & vbCrLf & vbCrLf & _
            "Application will exit.", vbCritical, "Restricted Access!"
    Application.Quit
    End If
    
    ErrorHandler:
    
    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Try:
    DoCmd.OpenForm "admin_menu"
    Or:
    DoCmd.OpenForm "admin_menu", acNormal, , , , acNormal
    Instead of:
    DoCmd.OpenForm "admin_menu", acNormal, "", "", , acNormal
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Nashaath is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10
    it doesn't work. tried 2 options u gave.

  4. #4
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Well i made a login system very similair to yours.
    I didnt check all of it but the line responcible for checking the password is the same but for a few details.
    Perhaps these details are the key.

    If Me.Password = DLookup("Password", "user", "UserID = '" & Me.cboUser.Value & "'") Then

    I also see call login, what does that do ?

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    1)What is the purpose of this line:
    strRole = DLookup("access_level", "user", "[UserID]'" & Me.cboUser.Value & "'")
    and what happens if you remove it.
    2)If you step through the code, what happens when it gets to the line that should open the form.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    Nashaath is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10
    call login, calls the function Public Sub login ()

  7. #7
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Did you try the modified line i gave ?

  8. #8
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    What format is your UserID field in your table ?
    Is it Autonumber ?, Text ?, Number ?

  9. #9
    Nashaath is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10
    yea i did try with the code you gave. but no luck yet.

    UserID field is Text

  10. #10
    Nashaath is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10
    i've uploaded my db...here is the link..please help to solve my problem... i need to login with three different level of users to three different forms..

    http://www.midupload.com/nhqnjzg9zva0

  11. #11
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Well that rules out that the line to check for the password is fault.
    Im beginning to think that your misplacing an "if" "else" or "elseif".

    I basicly have the same login system and mine works.

    Try to strip the code to that what is nessecary. WITHOUT the check for empty strings in the username and password.
    Just check for the password and then open the form in its basics like this :

    If Me.Password.Value = DLookup("Password", "user", "[UserID]='" & Me.cboUser.Value & "'") Then
    docmd.openform "admin_menu"

  12. #12
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Ohh the surf protecting of my work disables the content of your database
    Im really curious where your problem is haha.

  13. #13
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Can you attach a copy of your db in mdb (A2003) format.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  14. #14
    Nashaath is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10
    cannot convert it to earlier versions. due to macros

  15. #15
    Nashaath is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    10

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Login for a form. MACRO
    By louissmith in forum Access
    Replies: 0
    Last Post: 05-04-2012, 03:54 AM
  2. Replies: 1
    Last Post: 12-11-2011, 11:48 AM
  3. Login form with nt login
    By hitesh_asrani_j in forum Forms
    Replies: 6
    Last Post: 09-22-2011, 11:43 AM
  4. Login to a form?
    By tandkb in forum Forms
    Replies: 0
    Last Post: 04-25-2011, 06:05 PM
  5. Login Form
    By Kookai in forum Access
    Replies: 3
    Last Post: 10-18-2010, 04:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums