473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Login Form

145 100+
** 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
7 1903
NeoPa
32,556 Expert Mod 16PB
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
32,556 Expert Mod 16PB
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
32,556 Expert Mod 16PB
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
puT3
145 100+
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
puT3
145 100+
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
32,556 Expert Mod 16PB
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
32,556 Expert Mod 16PB
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

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

Similar topics

5
by: Simon | last post by:
Hi, I have a Login.php page that logs the user in and out. I has two forms within the page, (depending on what we are trying to do), either one to log in or out. The form calls itself using a...
1
by: John Davis | last post by:
I put a little login (username and password textfields) in a web page, and once the user able to login, I want the username and password textfields will disappear, and replace with text " has...
1
by: Wayne Smith | last post by:
Applies to: Microsoft FrontPage 2000, Microsoft Access 2000, IIS 5.0 Operating System: Microsoft Windows 2000 Professional I am trying to protect a portion of a web site by allowing users to...
3
by: Dam6 | last post by:
Okay... Using vb .net within DW MX2004, connecting to an access database: Background: I have created a simple login.aspx page that is supposed to re-direct to default.aspx using...
3
by: Bob | last post by:
I haver a user login form (winforms app using vs2005 in VB.NET). After succesfull validayion of user I want to open a first form and close the loging form that was used, If I write If...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
1
by: Kandiman | last post by:
Hiya, i made a asp page, and one of my divs (as a include) is as below. the problem is if the main page is resubmitted, i get logged out again?... heres the code.. i think its on the value=true...
10
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey...
21
by: tvnaidu | last post by:
This is the Java script I am using fo rlogin page, but cursor not pointing to login box, any idea how can I point cursor to login box when this page loaded?. here admin login take to control page and...
13
by: Apostle | last post by:
Hi all, after thinking for sometimes, I thought it will be great opportunity to learn if I will start from scratch and build my own register/login system. Here is the thread that I will be posting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.