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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting permissions through vb

Status
Not open for further replies.

Jorgandr

Programmer
May 10, 2002
58
US
I have set up to record who is logging in to my database based on their network log on. What is the procedure to set certain permissions depending on who logs on. I tried this code below:
Function SetVariables()
Dim rs As Recordset
Dim doc As Document
Dim db As Database
Dim con As Container

Set db = CurrentDb()
Set con = db.Containers("Tables")
Set doc = con.Documents("pnbdirectory")
Set rs = db.OpenRecordset("LoginInfoQuery", dbReadOnly)
doc.UserName = "Admin"
con.UserName = "Admin"
con.Documents.Refresh
Set doc = con.Documents("pnbdirectory")
con.Permissions = con.Permissions And Not dbSecReplaceData
rs.FindFirst "NetworkLogon = '" & Environ("UserName") & "'"
If Not rs.EOF Then
UserName = rs![FullName]
TimeLoggedIn = rs![TimeLoggedIn]
SecurityLevel = rs![SecurityLevel]
End If

If Environ("UserName") = "RhoadsGM" Or Environ("UserName") = "CookNT" Then
ElseIf Environ("UserName") = "EvansJS" Then

DoCmd.OpenForm "Startup Form"
 
Generally, when a database uses the Security Wizard to set up user security, administrators will create groups and assign the permissions to that group. As users are added they inherit those group permissions whenever the group is assigned to their username. For instance, all users have 'user' group permissions which could be anywhere from no permissions to all permissions. Permissions are not normally assigned during runtime operation based on usernames. I have a routine that assigns permissions to groups but only because all permissions are removed when the database is stored in SourceSafe. So when I build a version, I have to reestablish all the permissions for all the groups programmatically. This is done before using the database operationally. Your database does not have security and you are trying to set permissions to the default 'Admin' username on the fly. This could have some rather serious repercussions. Consider what happens if either of the users logs on concurrently and try to open the same form. Also, since you are using the only Admin username on your database, what will be the state of the permissions when the database is closed and reopened. Also you are hard coding system usernames into the database so you need to change code whenever someone comes/goes.

I can then use generic function like IsMemberOfGroup("Admins", CurrentUser) to keep from hard coding specific usernames.

----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top