Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login forms......How !!!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
hello der,

I am trying to have a login feature for the database I have built. Depending on the person logging in, he/she will be able to view specific information in various forms. eg an Admin person will get to see all d information as compared to a sales person who doesnt need to c the secure information.

Any suggestions as to how can this be done ? please !!
Thanks :)
 
Hi!

What you need is a table which contains, at the minimum, some designation(usually the network name) and the security level(Admin, Sales, Mgmt etc) for each individual. Most often a password is also included. I usually include an unbound form with text boxes to store the network ID and the security level of the user. If you include a password you will need to start out by asking for the network ID and the password and checking the information entered compared to the table and storing the information in the unbound form I mentioned above.

In the load procedures of your various forms you can do many different things, depending on the needs of the form. I usually include a menu form where I will hide certain options depending on the security level. From the menu form you can also filter the record source of other forms. In data entry/viewing forms, you can hide fields where appropriate or simply disable text boxes so the information can be viewed but not changed.

Obviously, this list of things just scratches the surface of what you can do with this method, but I hope it at least gives you a head start.

hth Jeff Bridgham
bridgham@purdue.edu
 
Hi,
I created a database using a table with user name, and process name. The process names are entered as fields in the table. This table contains usernames and processes which has "Y" or "N". Before a form or report opens, the system sign in name is checked against that table whether the particular user has authorization or not. if you want I can send you the code.

 
Hello jebry and rushdib,

Thanks for the quick reply :) I have got a table with username,password,category ie admin,sales etc.

i also have a login form but i dont know how to check the username and password entered by the user against the values in the table, i attempeted the following code but the type definition "database" was not recognised.

maybe the code which rushdib is referring to will assist, it wud be great if u can please email it to me on dt8@waikato.ac.nz . Tahnks once again.
The code -
Private Sub cmdLogin_Click()

Dim buffer As String * 50
Dim strUsername As String
Dim strPassword As String
Dim Trash As Long
Dim mLogOn
Dim myDB As Database
Dim myRS As Recordset
Dim mSrch As String
Dim mRecs As Long
Dim counter As Integer
Dim category As String

'store username & logon time
Set myDB = CurrentDb
Set myRS = myDB.OpenRecordset("tbUsers", dbOpenDynaset)
With myRS
mRecs = .RecordCount
'check to see if already logged on
strUsername = txtUsername.Text
strPassword = txtPassword.Text

While counter <= mRecs
If !Username = strUsername And !Password = strPassword Then
'If !category = &quot;Admin&quot; Then
frmClientEntryForm.Open
Else
counter = counter + 1
End If
End
End With
myDB.Close
Set myDB = Nothing

End Sub
 
Hello jebry and rushdib,

Thanks for the quick reply :) I have got a table with username,password,category ie admin,sales etc.

i also have a login form but i dont know how to check the username and password entered by the user against the values in the table, i attempeted the following code but the type definition &quot;database&quot; was not recognised.

maybe the code which rushdib is referring to will assist, it wud would you let me know. Tahnks once again.
The code -

Private Sub cmdLogin_Click()

Dim buffer As String * 50
Dim strUsername As String
Dim strPassword As String
Dim Trash As Long
Dim mLogOn
Dim myDB As Database
Dim myRS As Recordset
Dim mSrch As String
Dim mRecs As Long
Dim counter As Integer
Dim category As String

'store username & logon time
Set myDB = CurrentDb
Set myRS = myDB.OpenRecordset(&quot;tbUsers&quot;, dbOpenDynaset)
With myRS
mRecs = .RecordCount
'check to see if already logged on
strUsername = txtUsername.Text
strPassword = txtPassword.Text

While counter <= mRecs
If !Username = strUsername And !Password = strPassword Then
'If !category = &quot;Admin&quot; Then
frmClientEntryForm.Open
Else
counter = counter + 1
End If
End
End With
myDB.Close
Set myDB = Nothing

End Sub
 
I have done this many times...however I use straight Access code rather than recordsets...on the enter button on a login form I use dlookup to check whether the userid (or name) and password are in the UserTable. (dlookup only works in access. The isnothing function determins if the lookup is blank of not.)

I might then set a global variable equal to the user's level of access...again using dlookup to get it.

dlink = &quot;[UserID] = '&quot; & Me![txtUserId] & &quot;' AND [Password] = '&quot; & Me![txtPassword] & &quot;'&quot;

If Not IsNothing(DLookup(&quot;[UserName]&quot;, &quot;UserTable&quot;, dlink)) Then

This is no expert programmers answer but I find it effective.
 
The reason that the definition of database is not recognised is because you have to add the microsoft DAO 3.51 Library to the references of the project. In the code window go to tools, references. Make sure the priority of this library is greater than the microsoft ActiveX data objects library 2.1
 
Is it me, or would it not be simpler just to use the WorkGroup administrator, the builtin Access Security tools?

Thanks

CID8
 
Hi again!

Try this:

Dim rst As Recordset
Dim sql As String

sql = &quot;Select * From tblUsers Where UserName = '&quot; & txtUsername.Value & &quot;'&quot;
Set rst = CurrentDb.OpenRecordset(sql, dbSnapShot)

If rst.EOF = True and rst.BOF = True Then
Call MsgBox(&quot;The name you entered is not in the system. Please try again&quot;)
Call txtUserName.SetFocus
Else
If rst!Password = txtPassword.Value Then
Forms!frmSecurity!txtUser = rst!UserName
Forms!frmSecurity!txtLevel = rst!Category
DoCmd.OpenForm &quot;frmClientEntryForm&quot;
Else
Call MsgBox(&quot;The password and name do not match!&quot;)
Call txtPassword.SetFocus
End If
End If

Set rst = Nothing

Of course, you can get considerably more complicated than this depending on what level of security you are looking for. BTW, make sure you look at James79 message to take care of the error message you're getting.

hth Jeff Bridgham
bridgham@purdue.edu
 
I've been doing something a bit similar but have founf that I have to fill the VAriable pass word with the .value property not the .text eg.

If Me.txtPass.Value <> GetPass(Me.cboStaff) Then
STatements
End if

Might Help ?
cheers
Phill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top