469,336 Members | 5,592 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

User and Password in MS ACCESS

2
I am making a database program in MS Access I would to get help in giving a USER and PASSWORD in LOGIN Form. If the USER and PASSWORD is given in Table then we are entering the database else out of program or give an error.

I do not want to give the USER and PASSWORD to be mentioned in vb codes.

Please Help.


Kartik
Apr 4 '07 #1
14 13753
hi
if there are 2 textboxes namely name and psword and table name is logintable containing username and password fields which are texts then
then
If name = DLookup("username", "logintable", "[password]= '" & psword & "'") Then
do some thing
else Msgbox ""
Apr 4 '07 #2
Hi!!!

Is there any option because when i create a form linking to the table of login and enter everyone user and password, i want the user to to enter the username and password , if the user name and password matches the login table, then it should continue or else it should show an error message.

thanks & bye

Kartik
Apr 12 '07 #3
pks00
280 Expert 100+
enambo
Have u got a table created already?
here is an example

say u had a table called tblUsers, in it are two fields UserID and Pswd
Now a simple form example, u would have a form with two prompts txtUser and txtPswd and a button called cmdLogin

U would use the click event of cmdLogin to add your code

eg

Expand|Select|Wrap|Line Numbers
  1. private sub cmdLogin_Click()
  2.  
  3.     Dim sPswd as string
  4.  
  5.  
  6.     If IsNull(Me.txtUser) = True or IsNull(Me.txtPswd) = True then
  7.         msgbox "Please enter both a userid and password"
  8.         exit sub
  9.     end if
  10.  
  11.     'DLOOKUP returns null if no record found therefore give it a default value of ""
  12.     sPswd = NZ(DLOOKUP("Pswd","tblUsers","UserID='" & Me.txtUser & "'"),"")    
  13.  
  14.     If Me.txtPswd <> sPswd then
  15.         msgbox "Invalid UserID/Password combination"
  16.         exit sub
  17.     end if
  18.  
  19.     'Continue with normal successful login code
  20. end sub
  21.  


kartikss, sorry I havent quite undertstood your post, care to elaborate?
Apr 12 '07 #4
I have a question to add to this. Is it possible to carry that user ID for that user as long as they are logged into the DB so that anytime the user opens a form or report (ie also query) that it filters the data for that user.

I know this can be done using the Access built in security but I am trying to get away from that due to the environment.

Thanks in advance

Christian
Apr 18 '07 #5
pks00
280 Expert 100+
I have a question to add to this. Is it possible to carry that user ID for that user as long as they are logged into the DB so that anytime the user opens a form or report (ie also query) that it filters the data for that user.

I know this can be done using the Access built in security but I am trying to get away from that due to the environment.

Thanks in advance

Christian
define a global variable, then reference that
Apr 18 '07 #6
Shokoth
29
define a global variable, then reference that
How would we go about doing that.
What varialbe should we declare globally. is it the username (entered in a form), and the user name in the table?

then refer to it, where all the forms use that username?
Apr 19 '07 #7
Dude you may want to try this got this from the net, and i was able to use it

first create a table and name it tblEmployees, create the ff fields, lngEmpID(pk, AutoNumber),strEmpName(txt),strEmpPassword(txt),fu llname(txt),strAccess (text).

then create ur log on form frmLogon

using designview, insert a combobox, name it cboEmployee, and row source is SELECT tblEmployees.lngEmpID, tblEmployees.strEmpName FROM tblEmployees; on the after update event paste te ff code to set focus to textbox u wil create next,
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
txtPassword.SetFocus
End Sub

Now create ur password text box,

name it txtPassword.

Now insert a button and name it cmdLogin

Paste the code below on the on click event

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 "Switchboard"
'Create your switchboard or change this to any other form u want the user to see upon log in

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 your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub


You now have your Log in form

Hope i was able to help...good luck!
Apr 19 '07 #8
pks00
280 Expert 100+
rockdc1981

have a look at the code I posted. does that make sense to you?
its the same approach as the code you posted
Im hoping it makes sense to you so hopefully the OP understands it also
Apr 19 '07 #9
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command12_Click()
  2.  
  3.  
  4. If USER_ID = [Form_LOGIN MASTER].ID And PASSWORD = [Form_LOGIN MASTER].PWD Then
  5.  
  6. MsgBox (Form_Login.USER_ID + " - " + "WELCOME TO ENAM SECURITIES PVT LTD")
  7.  
  8.  
  9.  
  10.  Dim stDocName As String
  11.  Dim stLinkCriteria As String
  12.  
  13.   Me.Visible = False
  14.   DoCmd.OpenForm "STARTUP", acNormal, , , acFormEdit, acWindowNormal
  15.  
  16.  
  17.   stDocName = "STARTUP"
  18.   DoCmd.OpenForm stDocName, , , stLinkCriteria
  19.  
  20.  
  21. Else
  22.  
  23. MsgBox ("Incorrect User ID or Password - Please try again.")
  24.  
  25. End If
  26.  
  27.  
  28. End Sub 
PLS CHECK THE ABOVE CODE AND LET ME KNOW THE ERROR.
AS THIS WORK FINE. IT ACCEPTS ONLY FIRST RECORD AND NOT REST.
REST OF RECORD : I GET THE MESSAGE IE MsgBox ("Incorrect User ID or Password - Please try again.")

IS THERE ANY OTHER OPTION DO LET ME KNOW.

THANKS & BYE

KARTIK
Apr 19 '07 #10
meLady
27
Hello everyone,

Can anyone reply to kartikss's queries ... I am also interested in knowing the problems ... so, please reply to his question (^_^)
May 5 '07 #11
MMcCarthy
14,534 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command12_Click()
  2.  
  3.  
  4. If USER_ID = [Form_LOGIN MASTER].ID And PASSWORD = [Form_LOGIN MASTER].PWD Then
  5.  
  6. MsgBox (Form_Login.USER_ID + " - " + "WELCOME TO ENAM SECURITIES PVT LTD")
  7.  
  8.  
  9.  
  10.  Dim stDocName As String
  11.  Dim stLinkCriteria As String
  12.  
  13.   Me.Visible = False
  14.   DoCmd.OpenForm "STARTUP", acNormal, , , acFormEdit, acWindowNormal
  15.  
  16.  
  17.   stDocName = "STARTUP"
  18.   DoCmd.OpenForm stDocName, , , stLinkCriteria
  19.  
  20.  
  21. Else
  22.  
  23. MsgBox ("Incorrect User ID or Password - Please try again.")
  24.  
  25. End If
  26.  
  27.  
  28. End Sub 
PLS CHECK THE ABOVE CODE AND LET ME KNOW THE ERROR.
AS THIS WORK FINE. IT ACCEPTS ONLY FIRST RECORD AND NOT REST.
REST OF RECORD : I GET THE MESSAGE IE MsgBox ("Incorrect User ID or Password - Please try again.")

IS THERE ANY OTHER OPTION DO LET ME KNOW.

THANKS & BYE

KARTIK
How are you getting USER_ID and Password?
May 6 '07 #12
How are you getting USER_ID and Password?
Presently i am working with help of coding

for ex
Expand|Select|Wrap|Line Numbers
  1. private sub command1_click()
  2.  
  3. if id= form_login.id=kartik and pwd=form_login.password=123 or form_login.id=guest and form_login.password=g12 then
  4.  
  5. open the particular form
  6.  
  7. else
  8.  
  9. error message
  10.  
  11. endif
  12.  
  13. end sub
  14.  
  15.  
but now i want work with help of table name security control and table containing following details ie

userid (text), password (text), enable (y/n), visible (y/n)

if userid - enable = n then it should disable that option else it should enable
if userid - visible = n then it should disappear that option else it should appear

how do i work on this option

pls help me - urgently

if you require i will send the print screen of file.


Kartik
May 7 '07 #13
NeoPa
32,182 Expert Mod 16PB
How are you getting USER_ID and Password?
Presently i am working with help of coding

for ex
Expand|Select|Wrap|Line Numbers
  1. private sub command1_click()
  2.  
  3. if id= form_login.id=kartik and pwd=form_login.password=123 or form_login.id=guest and form_login.password=g12 then
  4.  
  5. open the particular form
  6.  
  7. else
  8.  
  9. error message
  10.  
  11. endif
  12.  
  13. end sub
  14.  
  15.  
but now i want work with help of table name security control and table containing following details ie

userid (text), password (text), enable (y/n), visible (y/n)

if userid - enable = n then it should disable that option else it should enable
if userid - visible = n then it should disappear that option else it should appear

how do i work on this option

pls help me - urgently

if you require i will send the print screen of file.


Kartik
Kartik,
If you do not reply correctly then you cannot expect any response.
You have not answered Mary's question.
You have simply asked the same question again and have posted some strange code with it that has never seen an Access database code window.
May 10 '07 #14
Denburt
1,356 Expert 1GB
I can only refer anyone back to post #4 I will repost the code that pks00 posted and try to add a few notes to help you understand. You need to take the values entered into the form then compare them to the information in the table. pks is using a function called DLookup, using this function he gathers the password information that is needed from the table for that particular user.

In this example you are telling DLookup to get the field information from "Pswd" in the table called "tblUsers" The final portion tells DLookup what the criteria is for pulling the one record you want so you can verify that the "Pswd" field matches the one on the form. Hence:"UserID='" & Me!txtUser & "'

The resulting password for me!txtUser will be stored in the variable sPswd for comparison purposes.

When in the VB window you can use the "debug.print sPswd" statement to verify you are picking up this information, the results will show in the immediate window if there are any to return.

Also in the VB window try highlighting the word DLookup and press F1.

Expand|Select|Wrap|Line Numbers
  1. private sub cmdLogin_Click()
  2.  
  3.     Dim sPswd as string
  4.  
  5.     If IsNull(Me!txtUser) = True or IsNull(Me!txtPswd) = True then
  6.         msgbox "Please enter both a userid and password"
  7.         exit sub
  8.     end if
  9.  
  10.     'DLOOKUP returns null if no record found therefore give it a default value of ""
  11.     sPswd = NZ(DLOOKUP("Pswd","tblUsers","UserID='" & Me!txtUser & "'"),"")    
  12. debug.print sPswd
  13.     If Me!txtPswd <> sPswd then
  14.         msgbox "Invalid UserID/Password combination"
  15.         exit sub
  16.     end if
  17.  
  18.     'Continue with normal successful login code
  19. end sub
Hope this helps.
May 10 '07 #15

Post your reply

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

Similar topics

reply views Thread by Adam Fortuno KOVICK | last post: by
1 post views Thread by notbob | last post: by
5 posts views Thread by Dave Kolb | last post: by
8 posts views Thread by Joe | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.