Record level access

G

Guest

anyone know how I can give certain users access only to certain records
within a database...too many forms and reports to redo for each user!...
 
S

Scott McDaniel

anyone know how I can give certain users access only to certain records
within a database...too many forms and reports to redo for each user!...

Enable User Level Security, add appropriate users and groups, allow access to the data only through your forms (i.e.
don't allow users direct access to the tables or queries), then filter the data based on user logins and group
membership. For example, if you have a DataEntry group who shouldn't see data relevant to Managers (which is indicated,
perhaps, by setting a table column named blnIsManager=True), then you'd something like this if the Open or Load event of
a form:

Sub Form_Open()

If faq_IsUserInGroup("DataEntry", CurrentUser) Then
Me.RecordSource = "SELECT Field1, Field2 etc FROM SomeTable WHERE blnIsManager=False"
Else
Me.RecordSource = "SELECT Field1, Field2 etc FROM SomeTable"
End If

End Sub

'/Note: the below was copied from the MS Access Security FAQ here:
http://support.microsoft.com/?id=14....aspx?scid=/support/access/content/secfaq.asp

Function faq_IsUserInGroup (strGroup As String, strUser as String) As Integer
' Returns True if user is in group, False otherwise
' This only works if you're a member of the Admins group.
Dim ws As WorkSpace
Dim grp As Group
Dim strUserName as string

Set ws = DBEngine.Workspaces(0)
Set grp = ws.Groups(strGroup)
On Error Resume Next
strUserName = ws.groups(strGroup).users(strUser).Name
faq_IsUserInGroup = (Err = 0)
End Function


Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
G

Guest

ok thanks for this, will give it a go!

Scott McDaniel said:
Enable User Level Security, add appropriate users and groups, allow access to the data only through your forms (i.e.
don't allow users direct access to the tables or queries), then filter the data based on user logins and group
membership. For example, if you have a DataEntry group who shouldn't see data relevant to Managers (which is indicated,
perhaps, by setting a table column named blnIsManager=True), then you'd something like this if the Open or Load event of
a form:

Sub Form_Open()

If faq_IsUserInGroup("DataEntry", CurrentUser) Then
Me.RecordSource = "SELECT Field1, Field2 etc FROM SomeTable WHERE blnIsManager=False"
Else
Me.RecordSource = "SELECT Field1, Field2 etc FROM SomeTable"
End If

End Sub

'/Note: the below was copied from the MS Access Security FAQ here:
http://support.microsoft.com/?id=14....aspx?scid=/support/access/content/secfaq.asp

Function faq_IsUserInGroup (strGroup As String, strUser as String) As Integer
' Returns True if user is in group, False otherwise
' This only works if you're a member of the Admins group.
Dim ws As WorkSpace
Dim grp As Group
Dim strUserName as string

Set ws = DBEngine.Workspaces(0)
Set grp = ws.Groups(strGroup)
On Error Resume Next
strUserName = ws.groups(strGroup).users(strUser).Name
faq_IsUserInGroup = (Err = 0)
End Function


Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top