Results 1 to 9 of 9
  1. #1
    ocm is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    39

    Login form


    Greetings,

    I’m trying to modify a login form that was developed by a former employee.
    I used the following code:
    Code:
    Private Sub cmdLOGIN_Click() 'Check to see if data is entered into the UserName and password box matches to tblLOGIN If IsNull(Me.txtUserNm) Then MsgBox "Please enter User Name", vbOKOnly, "Required Data" Me.txtUserNm.SetFocus ElseIf IsNull(Me.txtPWD) Then MsgBox "Please enter Password", vbOKOnly, "Required Data" Me.txtPWD.SetFocus Else 'Check to see if data entered into the UserName and Password box matches to tblLOGIN If (IsNull(DLookup("USERNM", "tblLOGIN", "USERNM = '" & Me.txtUserNm.Value & "' And PWD = '" & Me.txtPWD.Value & "'"))) Then MsgBox " **Invalid Username or Password **!" Exit Sub Else MsgBox "Password Is Invalid - Try Again!", vbCritical + vbOKOnly, "INVALID PASSWORD" Me.txtInvalidPW = "Y" Me.txtAttempts = Me.txtAttempts + 1 If Me.txtAttempts = 3 Then MsgBox "Check Password And Try Again" & vbCrLf & " GOOD-BYE", vbCritical + vbOKOnly, "TRY AGAIN LATER" Exit Sub DoCmd.Quit Else Me.txtPWD.SetFocus Me.cmdLOGIN.Enabled = False End If Exit Sub
    I’ve attached a summary document to show my test result and mods. I would like to see.

    Click image for larger version. 

Name:	test result.png 
Views:	68 
Size:	23.5 KB 
ID:	34744
    Any suggestions?

    TIA

    Regards,

  2. #2
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Looks good, The indentation could use some cleanup.

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Basically, you have to code for whatever explicit inputs and variables (such as attempt counts) that you want to deal with, which can get long in code, while trying to figure out what a user might do - accidentally or not. The following line is really 2 tests separated by OR not by AND. Your line suggests there can be a case of no user name, yet you expect a password to be there.
    If (IsNull(DLookup("USERNM", "tblLOGIN", "USERNM = '" & Me.txtUserNm.Value & "' And PWD = '" & Me.txtPWD.Value & "'")))

    I had to guess at password field & move stuff around, so I may have goofed on the following suggestion. Regardless, the point is that it is 2 separate tests because there are 2 possibilities that you are looking at:
    If IsNull(DLookup("USERNM", "tblLOGIN", "USERNM = '" & Me.txtUserNm.Value)) & "' OR IsNull(DLookup("PWD", "tblLOGIN",PWD = '" & Me.txtPWD.Value & "'"))

    Depending on your approach, the tests might be split so as to deal with each part separately. HOWEVER, unless you're dealing with a shared computer situation (such as in a school and cannot rely on users logging out of the pc) then why bother with the hassle of password forms and users who forget them? Simply lookup the Windows login ID from your table. If it's there, they get in. If not, they don't. It's easy to know this - Google fosUserName and make sure you find a 64 bit version if you're not using 32 bit.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    ocm is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    39
    Thank you for your feedback.
    Micron,
    Your line suggests there can be a case of no user name, yet you expect a password to be there.
    No, everyone must have a user name (FirstInitialLastName) and a password (I provide users what their password is). Users often forget their password and keep trying so many different passwords that doesn’t exist. I would like to give them three attempts and get a prompt to contact the administrator.

    The following line is really 2 tests separated by OR not by AND.
    I tried the following syntax and got Compile error, Syntax error
    Code:
    If IsNull(DLookup("USERNM", "tblLOGIN", "USERNM = '" & Me.txtUserNm.Value)) & "' OR IsNull(DLookup("PWD", "tblLOGIN",PWD = '" & Me.txtPWD.Value & "'")) Then  MsgBox " **Invalid Username or Password **!"
    TIA

    Regards,

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    No, everyone must have a user name (FirstInitialLastName) and a password
    I realize your intent, but that is not what your expression suggests. To paraphrase your code:
    IF there is no username in the table AND PWD = value in the form password control.
    So if there's no user name in the table that matched a form control, why would you add the AND condition that there would be a password for no user name? That's why it's an OR condition.
    IF there is no username in the table OR the password doesn't match then show generic message that there is an issue with one or both.
    Code:
    '" & Me.txtUserNm.Value))
    In the first case, your closing ' is after the parentheses, which means they (the ))) become part of the criteria. Also, there are no beginning quotes for PWD. I see that I made those mistakes in the previous post. Good thing I put that disclaimer in there. Perhaps
    Code:
    If IsNull(DLookup("USERNM", "tblLOGIN", "USERNM = '" & Me.txtUserNm & "')) OR IsNull(DLookup("PWD", "tblLOGIN","PWD = '" & Me.txtPWD & "'"))" Then  
    MsgBox " **Invalid Username or Password **!"
    Still, I don't see the wisdom in what you're doing, but perhaps that's what you've been told to do. As a user, I might want more than 3 attempts, notwithstanding the fact that I'd avoid the password thing altogether if it were up to me. I could probably break in and read your passwords without too much difficulty.

    EDIT: BTW, you don't need .Value for a textbox (and some other controls) as .Value is the default property. You'll see that I removed it as an FYI thing.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    ocm is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    39
    Thanks,
    I used the modified syntax and still get Compile error: syntax error.
    Code:
    'Check to see if data entered into the UserName and Password box matches to tblLOGIN
      If IsNull(DLookup("USERNM", "tblLOGIN", "USERNM = '" & Me.txtUserNm & "')) OR IsNull(DLookup("PWD", "tblLOGIN","PWD = '" & Me.txtPWD & "'"))" Then
      MsgBox " **Invalid Username or Password **!"
    As for the login attempt, I see your point, I did increase it to 5 attempts.

    TIA

    Regards,

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    My apologies, I seem to not be able to split my attention between this task and the tv (world series recording).

    It looks like there is one too many ending quotes in the second DLookup "'"))" vs "'"))

    However, you can see that the first DLookup doesn't look the same as the second and might have drawn a clue from that. Makes me think you're not trying any harder than me and are watching tv too! BTW, knowing what the error message is often helps to focus a response. Maybe what you got has nothing to do with what appears to be the current issue??

  9. #9
    ocm is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    39
    Thanks for pointing out the issue. You are correct in that my attention was split between my job relates tasks and catching up with world cup. I made some adjustment and verified that users can not access the DB without entering user name and password. For now, the management are okay with the result.
    I do appreciate all your help!

    Regards,

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

Similar Threads

  1. Replies: 4
    Last Post: 07-17-2015, 10:04 AM
  2. Replies: 2
    Last Post: 04-17-2015, 10:59 AM
  3. Replies: 3
    Last Post: 03-17-2014, 10:23 AM
  4. Replies: 1
    Last Post: 12-11-2011, 11:48 AM
  5. Login form with nt login
    By hitesh_asrani_j in forum Forms
    Replies: 6
    Last Post: 09-22-2011, 11:43 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
  •  
Other Forums: Microsoft Office Forums