Results 1 to 4 of 4

Login Screen in Access

  1. #1
    Join Date
    Nov 2005
    Posts
    1

    Login Screen in Access

    Hello everyone,

    I've been trying to creat a login screen in access but its giving me some trouble. I already designed the form but apparently my code is not working. I tried this :


    Code:
       Dim strUserName As String
        Dim strPassword As String
        Dim stDocName As String
        Dim stLinkCriteria As String
      
    
        txtPassword.SetFocus
        If IsNull(txtPassword) Then
            MsgBox "Missing password"
            Exit Sub
        Else
            strPassword = txtPassword
        End If
        
        txtUserName.SetFocus
        If IsNull(txtUserName) Then
            MsgBox "Missing name"
            Exit Sub
        Else
            strUserName = txtUserName
        End If
    
        
      
      
       txtPassword.SetFocus
    
        If txtPassword <> "p" Then
        MsgBox "Wrong password"
            Exit Sub
            Else
             stDocName = "frmSwitchboard"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
            Me.Visible = False
            txtPassword.Text = Clear
        End If
            
            txtUserName.SetFocus
            If txtUserName <> "d" Then
            MsgBox "Wrong UserName"
            Exit Sub
            Else
             stDocName = "frmSwitchboard"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
            Me.Visible = False
            txtUserName.Text = Clear
            
      End If
       
    Exit_cmdOk_Click:
        Exit Sub
    
    Err_cmdOk_Click:
        MsgBox Err.Description
        Resume Exit_cmdOk_Click
        
    End Sub
    My problem is when i enter a password or a user name other than the ones specified by the code it displays the message then opens the switchbard anyways. I want it to display the message then go back to the login screen (with the previously entered values erased).

  2. #2
    data808 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Aug 2012
    Posts
    476
    If txtusername = "user1" and txtpassword = "pass1" then
    docmd.openform "form name"
    else
    msgbox "wrong username or password"
    end if

  3. #3
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    You might wanna Put your Usernames and passwords stored in a table.
    If you wanna expand your custom login features it will be more easy to do.
    My application has all the features a normal web based login screen has, like three chances to login, or be be cut off from the application. A password expiration date. A feature to alter your own password, and more.
    Without storing it in a table it would be next to impossible to do.
    Here is a sample for my login procedure (without the above mentioned).
    If you wanna expand it more, let me know.

    Code:
    If IsNull(Me.UserName) Then
    MsgBox "Username required"
    Exit Sub
    Else
    If IsNull(Me.Password) Then
    MsgBox "Password required"
    Exit Sub
    End If
    End If
    If Me.fldEnterPassword.Value = DLookup("Password", "tblLogin", "Group = '" & Me.UserName.Value & "'") Then
    DoCmd.Close
    DoCmd.OpenForm "OpenYourForm", acNormal
    Else
    MsgBox "Invalid password"
    End If

  4. #4
    data808 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Aug 2012
    Posts
    476
    I agree with JeroenMioch. I just got a lot of help from someone on here to finish a login in form that has its users saved to a table and its a whole lot better.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How do I undo the requirement to login every mdb
    By garymkrieg in forum Security
    Replies: 3
    Last Post: 07-11-2011, 03:53 PM
  2. Database Login Error
    By narasareddy in forum Access
    Replies: 0
    Last Post: 08-30-2008, 12:00 AM
  3. Replies: 1
    Last Post: 01-04-2008, 11:40 AM
  4. Query datasheet screen
    By Scott in forum Queries
    Replies: 0
    Last Post: 08-07-2007, 03:22 AM

Posting Permissions

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