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

Restrict multiple logins with single username at sametime in ms access

P: 20
Hi all

I have a mdb with login name and password form. There are several login names, i defined through a table "User_login". Here the problem is at a time a single user is able to login in multible system, which i want to restrict.

here is the code which i i am using for login check.....

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmblogin_Click()
  2.  
  3. Static intlogonattempts As Integer
  4.  
  5. 'Check to see if data is entered into the UserName combo box
  6.  
  7.     If IsNull(Me.cmbname) Or Me.cmbname = "" Then
  8.       MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
  9.         Me.cmbname.SetFocus
  10.         Exit Sub
  11.     End If
  12.  
  13.     'Check to see if data is entered into the password box
  14.  
  15.     If IsNull(Me.cmbpass) Or Me.cmbpass = "" Then
  16.       MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
  17.         Me.cmbpass.SetFocus
  18.         Exit Sub
  19.     End If
  20.  
  21.     'Check value of password in tblEmployees to see if this
  22.     'matches value chosen in combo box
  23.  
  24.  
  25.  
  26.         If Me.cmbpass.Value = DLookup("Password_login", "user_login", "[id]=" & Me.cmbname.Value) Then
  27.  
  28.  
  29.             emp_name = Me.cmbname.Value
  30.  
  31.             intlogonattempts = 0
  32.  
  33.             'Close logon form and open splash screen
  34.  
  35.             cmbname.SetFocus
  36.             Me.Visible = False
  37.             DoCmd.OpenForm "As Laid Backlog Digitization Database"
  38.  
  39.  
  40.         Else
  41.           intlogonattempts = intlogonattempts + 1
  42.  
  43.           If intlogonattempts > 3 Then
  44.             MsgBox "Sorry! You do not have access to this database.Please contact admin.", vbCritical, "Restricted Access!"
  45.             Application.Quit
  46.  
  47.          End If
  48.  
  49.           MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
  50.           Me.cmbpass.SetFocus
  51.  
  52.           End If          
  53. End Sub
  54.  

can anyone please help on this..........


Regards
yuvan

<E-mail address removed>
Oct 7 '08 #1
Share this Question
Share on Google+
17 Replies


NeoPa
Expert Mod 15k+
P: 31,419
You don't say :
What problem you're having.
What error messages you're getting.
What line the error message is on.
Oct 7 '08 #2

NeoPa
Expert Mod 15k+
P: 31,419
Assuming [cmbName] holds a string value, try changing line #26 of your code to :
Expand|Select|Wrap|Line Numbers
  1. If Me.cmbPass = DLookup("Password_login", "user_login", "[id]='" & Me.cmbname & "'") Then
Oct 7 '08 #3

NeoPa
Expert Mod 15k+
P: 31,419
To ensure the same user only logs in once at a time, add a field into your [User_Login] table that indicates if the user is currently logged in. You will need to set it to TRUE after a successful login, and test for that too when checking the name and password.

You will also need a facility to reset any or all names in case the system crashes at any point.
Oct 7 '08 #4

P: 20
Hi Neopa,

My problem is a person with the login name "A" is able to login into "N" number of systems at a time. i want to restrict that through VB code. Can you please help on this...........
Oct 16 '08 #5

NeoPa
Expert Mod 15k+
P: 31,419
You don't say :
What problem you're having.
What error messages you're getting.
What line the error message is on.
You answer none of my questions. You don't respond to (ignore) the help I've already posted. Now you want me to start again from scratch.

I understand your basic problem. I need you to respond to my posts before I spend any more time on this. Is that too much to ask? It is your question after all.
Oct 16 '08 #6

P: 20
Sorry.... I was out of internet facility for one week at the time of your reply. So that i couldn't able to response to you in right time................
Oct 17 '08 #7

NeoPa
Expert Mod 15k+
P: 31,419
Timing is not a problem, but when you do reply, I still need you to answer the questions. Without all those answers I am unable to help further.
Oct 17 '08 #8

P: 20
What problem you're having.
Problem that is a person is able to login in several systems by using same login. That I want to restrict..........
What error messages you're getting.
No error messages.
What line the error message is on
All the lines are working fine. I gave th code just for your reference.
Oct 17 '08 #9

NeoPa
Expert Mod 15k+
P: 31,419
Thank you. Now we can progress.

The next question then (in response to the information) is what did you think about post #4. It seems to me this may well be a solution to the problem you've described.
Oct 17 '08 #10

P: 20
i too thing that will work. But i don't know how to do that..........
Oct 17 '08 #11

NeoPa
Expert Mod 15k+
P: 31,419
OK Let's take this step by step.

Do you have a table of accounts that can be used to log on? What is its name?
Oct 17 '08 #12

P: 20
Table name is "user_login"
Oct 18 '08 #13

NeoPa
Expert Mod 15k+
P: 31,419
Sorry, that info was already available from the OP (Original Post). Never mind.

The next question is :
What are the names of all the fields you have in that table now?

This will work much better if you can post the meta-data (info about the layout / structure) of the table in the same way as I use in my example. Click on the Reply button and you will have access to all the codes I've used. PK & FK stand for Primary Key & Foreign Key respectively. Never use TABs in this as the layout gets mucked up. Use spaces and all is fine.
Table Name=[User_Login]
Expand|Select|Wrap|Line Numbers
  1. Field           Type      IndexInfo
  2. UserID          AutoNumber    PK
  3. Account         String      Unique
  4. Password        String
  5. FullName        String
  6. InUse           Boolean
This example is a basic layout and includes the items you will need ([FullName] not ABSOLUTELY necessary). You need to post what you have in your table in this layout.
Oct 19 '08 #14

P: 20
Hi

here is my table detail

Table Name=[User_Login]
Expand|Select|Wrap|Line Numbers
  1. Field             Type      IndexInfo
  2. ID                Number        PK
  3. EMP_NAME          String      Unique
  4. Password_Login    String
  5. InUse             Boolean
Oct 20 '08 #15

NeoPa
Expert Mod 15k+
P: 31,419
That looks sensible enough.

Looking at your code in the OP (Original Post) I can't see how you're trying to get this to work. You have a Click event procedure for a ComboBox control (cmbLogin) :S I would have expected a Command Button type control (cmd...).

Can you clarify which controls you have on your form for me please, and how a user logs in.
Oct 20 '08 #16

P: 20
Yes, your guess is correct. The command button is named as "cmblogin".
Oct 21 '08 #17

NeoPa
Expert Mod 15k+
P: 31,419
Can you clarify which controls you have on your form for me please, and how a user logs in.
Please answer the questions so that we can continue.
Oct 21 '08 #18

Post your reply

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