By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

Login Form

100+
P: 145
** Admin Edit - Thread split from To search record **

alright,i will try...

Another is I want to add user login form in my database,I know that there are many threads about this but I still dont understand it...I already create table name [UserConfig]

where it has the following
Expand|Select|Wrap|Line Numbers
  1. lngID,PK,Autonumber
  2. UserName,Text
  3. IsAdmin,Text
  4. Password,Text
  5.  
and a form name [frmLogin] with the following
Expand|Select|Wrap|Line Numbers
  1. cmbUserName,ComboBox
  2. txtPassword,TextBox
  3. btnLogin,Button
  4.  
I already insert this code
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnLogin_Click()
  2.  
  3.     If IsNull(Me.cmbUserName) Or Me.cmbUserName = "" Then
  4.         MsgBox "Please enter UserName", vbOKOnly, "Required"
  5.         Me.cmbUserName.SetFocus
  6.         Exit Sub
  7.     End If
  8.  
  9.     If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
  10.         MsgBox "Please enter Password", vbOKOnly, "Required"
  11.         Me.txtPassword.SetFocus
  12.         Exit Sub
  13.     End If
  14.  
  15.     If Me.txtPassword.Value = DLookup("Password", "UserConfig", "[lngID]=" & Me.cmbUserName.Value) Then
  16.         lngID = Me.cmbUserName.Value
  17.  
  18.     Else
  19.         MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry"
  20.         Me.txtPassword.SetFocus
  21.     End If
  22.  
  23.     Exit Sub
  24.  
  25.     intLogonAttempts = intLogonAttempts + 1
  26.     If intLogonAttempts > 3 Then
  27.         MsgBox "You do no have access to this database.", vbCritical, "Restricted Access!"
  28.         Application.Quit
  29.     End If
  30.  
The problem im having are I dont where to put this code which to compare the level of user so that some user will be able to open all form
Expand|Select|Wrap|Line Numbers
  1. If DLookup("IsAdmin", "UserConfig", "[lngID]=" & Me.cmbUserName.Value = "Yes") Then
  2.         ...'Coding for allowing access to application/form(I do not know)
  3.     Else
  4.  
  5.     If DLookup("IsAdmin", "UserConfig", "[lngID]=" & Me.cmbUserName.Value = "No") Then
  6.         ...'Coding for allowing access to application/form(I do not know)
  7.     End If
  8.  
  9.     DoCmd.OpenForm "MAIN MENU"
  10.     DoCmd.Close acForm, "frmLogin", acSaveNo
  11.  
...and how to to make the coding for allowing certain application/form for certain user...For example,administrator will have access for all but the user only have access for search form....

I try this code to test to see it work or not
Expand|Select|Wrap|Line Numbers
  1.  If DLookup("IsAdmin", "UserConfig", "[lngID]=" & Me.cmbUserName.Value = "Yes") Then
  2.         MsgBox "You are a Administrator", vbOKOnly
  3.     Else
  4.  
  5.     If DLookup("IsAdmin", "UserConfig", "[lngID]=" & Me.cmbUserName.Value = "No") Then
  6.         MsgBox "You are a User", vbOKOnly
  7.         Exit Sub
  8.     End If
  9.  
  10.     DoCmd.OpenForm "MAIN MENU"
  11.     DoCmd.Close acForm, "frmLogin", acSaveNo
  12.  
but when click the button nothing happen...

Sorry for asking this question again....
Sep 25 '08 #1
Share this Question
Share on Google+
7 Replies


NeoPa
Expert Mod 15k+
P: 31,349
Let me start by saying that, because you have included a good deal of relevant info in your first post on this subject, helping you along will be MUCH easier than before. We win - You win :)

Let's start by highlighting the first issue I see then (We can move onto others when I find them).

When testing form control values for being empty, simply check IsNull() for the name of the control. The .Value is the default property anyway. Thus, your first batch could be :
Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me.cmbUserName) Then
  2.     MsgBox "Please enter UserName", vbOKOnly, "Required"
  3.     Me.cmbUserName.SetFocus
  4.     Exit Sub
  5. End If
Sep 25 '08 #2

NeoPa
Expert Mod 15k+
P: 31,349
After line #13 you need to add in :
Expand|Select|Wrap|Line Numbers
  1. intLogonAttempts = 0
Otherwise, it will remember failed attempts, even after a successful logon.

By the way, you don't include the Dimming of intLogonAttempts. I assume it is module level.
Sep 25 '08 #3

NeoPa
Expert Mod 15k+
P: 31,349
How you manage access to various objects (forms etc) is really very much dependent on your intentions and design. For instance, where and how are you storing the operator's identity?

The checks should be done whenever attempting to access a resource. This can either be hard-coded into the resource itself (a form's Form_Open() event) or into the calling code that opens the form. An alternative to hard-coding is to dhave a system where your configuration is stored in a table.
Sep 25 '08 #4

100+
P: 145
This the code after few changes,not much...
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Command6_Click()
  4.  
  5.     Dim intLogonAttempts As Integer
  6.  
  7.     If IsNull(Me.cmbUserName) Or Me.cmbUserName = "" Then
  8.         MsgBox "Please enter UserName", vbOKOnly, "Required"
  9.         Me.cmbUserName.SetFocus
  10.     Exit Sub
  11.     End If
  12.  
  13.     If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
  14.         MsgBox "Please enter Password", vbOKOnly, "Required"
  15.         Me.txtPassword.SetFocus
  16.     Exit Sub
  17.     End If
  18.  
  19.     If Me.txtPassword.Value = DLookup("Password", "UserConfig", "[lngID]=" & Me.cmbUserName.Value) Then
  20.         lngID = Me.cmbUserName.Value
  21.         intLogonAttempts = 0
  22.     Else
  23.         MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry"
  24.         Me.txtPassword.SetFocus
  25.     End If
  26.     Exit Sub
  27.  
  28.     intLogonAttempts = intLogonAttempts + 1
  29.     If intLogonAttempts > 3 Then
  30.         MsgBox "You do no have access to this database.", vbCritical, "Restricted Access!"
  31.         Application.Quit
  32.     End If
  33.  
  34.     End Sub
  35.  
Sep 26 '08 #5

100+
P: 145
How you manage access to various objects (forms etc) is really very much dependent on your intentions and design. For instance, where and how are you storing the operator's identity?

The checks should be done whenever attempting to access a resource. This can either be hard-coded into the resource itself (a form's Form_Open() event) or into the calling code that opens the form. An alternative to hard-coding is to dhave a system where your configuration is stored in a table.
I store the operator identity in a table as i mention previously...hmm...I dont really understand,can u give some example about this
"An alternative to hard-coding is to dhave a system where your configuration is stored in a table."

I want administrator to have the access to add,update,delete and search form while user only have the access for the search form...do i need to insert this in the table because there are about many form...
Sep 26 '08 #6

NeoPa
Expert Mod 15k+
P: 31,349
From your psted code I would make the following comments :
  1. Add the line "Option Explicit" after "Option Compare Database".
  2. Set this as the default (From VBA Editor select Tools / Options / Editor Tab / Require Variable Declaration).
  3. Compile your code (always) before posting it. This avoids confusion as we expect any posted code to be compiled unless otherwise stated.
  4. You are still comparing controls against "". As far as I'm aware this is never a possible value. This is not exactly wrong. It's simply wasting time and makes the code harder to understand easily.
  5. intLogonAttempts needs to be declared in one of two ways (The way you have it won't work as there is no looping within the procedure itself. Every time it is called intLogonAttempts will be reset to 0 before the code executes).
    1. Declare it as Private in the module OUTSIDE of any procedures (preferably before any of your code).
    2. Declare it as Static within the procedure itself. Simply replace Dim intLogonAttempts As Integer with Static intLogonAttempts As Integer.
    I recommend looking up Private & Static in Access Help.
Sep 26 '08 #7

NeoPa
Expert Mod 15k+
P: 31,349
I store the operator identity in a table as i mention previously...hmm...I dont really understand,can u give some example about this
I am referring to something which remembers, not what operators are available, but which operator has already been successfully verified and is now logged on. This is session level information. It would not be a good idea to store this in a table, as otherwise other users would have access to it simply because someone else is already logged on at another PC.
"An alternative to hard-coding is to have a system where your configuration is stored in a table."

I want administrator to have the access to add,update,delete and search form while user only have the access for the search form...do i need to insert this in the table because there are about many form...
If you want different forms to have different sets of operators that can access them, then you will either need to check the logged in operator (they shouldn't need to log in again every time they go to a new form) within each different form, or you will need to design a system based on a table which stores which operators are allowed for each form.

Does that make it clearer?
Sep 26 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.