Log In Form

unclefink

Registered User.
Local time
Yesterday, 23:49
Joined
May 7, 2012
Messages
184
I am working on attempting to create user access into a database i've created. I've found directions for making a form and all necessary steps at http://www.databasedev.co.uk/login.html

I've followed the directions all the way through and it works for exactly what I want to a point.

There is one thing that is not working and another I was wondering if someone could help me add to this subject matter.

The first issue I am experiencing is when someone puts in the incorrect password more than 3 times, the program is not closing as it should but continuing to allow the user to enter new password over and over again without closing.

Here is the code for the button that is meant to compair the "Username" and "password", it works great if you know the username and associated password.

Code:
Private Sub cmdLogin_Click()

'Check to see if data is entered into the UserName combo box

    If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
      MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
        Me.cboEmployee.SetFocus
        Exit Sub
    End If

    'Check to see if data is entered into the password box

    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
      MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
        Me.txtPassword.SetFocus
        Exit Sub
    End If

    'Check value of password in tblEmployees to see if this
    'matches value chosen in combo box

    If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", _
            "[lngEmpID]=" & Me.cboEmployee.Value) Then

        lngMyEmpID = Me.cboEmployee.Value

        'Close logon form and open splash screen

        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "frmSplash_Screen"

    Else
      MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If

    'If User Enters incorrect password 3 times database will shutdown

    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
      MsgBox "You do not have access to this database.Please contact admin.", _
               vbCritical, "Restricted Access!"
        Application.Quit
    End If

End Sub

Is anyone able to help me out as to why its not shutting down after three unsuccessfull attempts.

The second thing i'd like to add onto this is having access to specific items within the database depending on the person.

For example, I would want 2 administrators with all access, one data entry person, and anyone else read only. Any suggestions?
 
On the first issue, intLogonAttempts would appear to be a public variable (it is not declared in the code you have posted). Has this been declared elsewhere?

On the second there are a multitude of methods to do this, several have been looked at only recently on this forum. Have a quick search and see what you turn up. If you do not find anything or have trouble applying to your scenario come back and ask further, we will help you out.
 
Regarding the first issue, I dont believe its declared anywhere else. I just followed all the steps provided and its the only place I recall seeing it.

Thank you for the direction and feedback.
 
In reply to the first issue... You need to be *greater than* 3 in order for the database to close. So perhaps you want to say *equal to* 3

If intLogonAttempts = 3 Then
 
In reply to the first issue... You need to be *greater than* 3 in order for the database to close. So perhaps you want to say *equal to* 3

If intLogonAttempts = 3 Then


I changed the information where it appears it should be changed; however it then closes after the
first invalid attempt!

Code:
'If User Enters incorrect password 3 times database will shutdown
 
    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts = 3 Then
      MsgBox "You do not have access to this database.Please contact admin.", _
               vbCritical, "Restricted Access!"
        Application.Quit
    End If
End Sub

Am I changing the incorrect information?
 
Yes, you are but I guess it didn't like that so let's do...

If intLogonAttempts > 2 Then
 
That makes it do what it was doing origionally. Allows one to cycle a new password over and over and over again without shutting down.
 
Okay, hold on... I use a different LogOn module. So let me go get this one...
 
Please put this at the top of your forms code module (under your Option declarations)...

Private intLogonAttempts As Integer

I see by your previous post, which I did not read prior, you may ot have that line...
 
I really thank you very much for your help on this and I really apologize for being clueless as I am utilizing all the information i've received on this website, books, and trial and error to self teach myself this program.

I've not really gotten into the vba coding as far as understanding what any of this stuff means. The above noted code is something I found on a web site and as indicated works for the most part.

That being said, where should I add this line. In the module or the button executing the form where the rest of the code is?

If it helps at all, I got the step by step information at this link http://www.databasedev.co.uk/login.html

Thanks again for the help, its been a challenge to learn. Are there any beginnners books you would reccomend for learning this code to which I understand is also vba; however correct me if im wrong on that.
 
You add that line right under...

Code:
Option Compare Database
Option Explicit
Private intLogonAttempts As Integer

...behind the same form you placed the below code.

The site you got the code from has a sample file to download. While the site has 99.9% of the code, the sample file has the balance, like the bolded line above. I went to the site, got the sample file and tested it. Since it works as expected AND I see that line is missing from your posted code I am suggesting adding that line as it is probably the reason it doesn't work.
 
My browser timed out and logged me out but it looks like youve answered before I was able to get back in.

Gina,

I figured out what you were talking about in reference where to put that line and BAM, exactly what it was missing. I wish I really knew what any of this coding stuff meant and knew what to put where rather than copying it from step by step directions. Thank you very much again for the help. I am still however interested in a book that might be good for self teaching. I'm sure a lot of what i'm doing is normally at an advanced level, at least thats what i'm telling myself. Hopefully that is the case.

ISSKNT, I just went back to your initial response to this post and I now see what it was that you were talking about. I presume the line of code suggested by Gina was the declaration line you were referring to.

Thanks again to both of you, any and all help, suggestions, or direction are all appreciated.

Now onto my next task, (problem 2 noted above)!!!

Respectfully,
 
ISSKNT, I just went back to your initial response to this post and I now see what it was that you were talking about. I presume the line of code suggested by Gina was the declaration line you were referring to.
biggrin.gif
biggrin.gif
We all learn through trial and error i guess. At least your query (#1) has now been resolved.

A hint on #2? An extra field in your users table to say what forms they are allowed to access???
 
Oh dear, I forgot all about #2 until I read Isskint's reply. Do you have a Users table? If yes, what fields are in it?
 
My current "Employees" table is exactly like the one on that page referenced earlier.

table is titled tblEmployees

Field 1=EmployeeID/Autonumber
Field 2=Employee Name
Field 3=Password

I suspect I need to identify what I want individuals to have to which i've been contemplating throughout the day.

Ultimately I would like two "administrator" log ins, access to the entire db.

A Super user who should have access to everything except the database structure. IE: this super user should have access to all forms, reports, and queries referencing such.

The third group should be read only with access to only specific forms. This group will not be doing data entry, only data reference.

Hopefully this makes sense. As referenced by Issknt, I figured I would need to add a new field to identify what each individual should have access to however I am not entirely sure how to reference each item to each user.

I'll check my local library for any of those books referenced, this is a fun brain teaser, i'm sure its much easier had I taken some sort of class but thats what challenges are for. I used to play with HTML and created a web page with such before my oldest daughter was born, something i randomly picked up on. I'm sure this will be something I will enjoy working with after picking, understanding, and appying the basics.

Thanks again to both of you for your generious time and patience.

Respectfully, :banghead:
 

Users who are viewing this thread

Back
Top Bottom