I'm not an expert on MS Access security, but here goes...
First, how familiar are you with creating and setting User Level Security in Access? What you want to do is possible, but will involve the implementation of security. There is a wizard that will automate much of it.
So basically you need to test whether the current user is a member of the Admins group, and change the record source of your form accordingly. However, there is a big gotcha here. In your post you seemed to imply that certain members would have access only to the form, and Admins would have access to the form and the table. This won't work - in order to view and/or manipulate the data via a form, the user must also have the necessary permissions for the form's record source. So if the user can see the data in the form, he/she can also open the table. You can, of course, limit what the user is able to do to the data, i.e. read only, add records, update records, etc.; and you can take measures to hide the database window. But for the form to work properly, you will need to assign the same level of permission to the underlying object, i.e. the table and/or query.
If you still wish to pursue this route, here's one way to achieve it.
1) Create a module and paste in the following code:
Code:
Function GetCurrentUserGroups() As String
Dim wrk As Workspace
Dim usr As User
Dim grp As Group
Dim strGroups As String
On Error Resume Next
Set wrk = DBEngine.Workspaces(0)
Set usr = wrk.Users(Application.CurrentUser)
For Each grp In usr.Groups
strGroups = strGroups & grp.Name & ","
Next grp
GetCurrentUserGroups = Left(strGroups, InStrRev(strGroups, ",") - 1)
End Function
Function InGroup(ByVal strGroup As String) As Boolean
Dim varGroups As Variant
Dim i As Integer
varGroups = Split(GetCurrentUserGroups(), ",")
For i = 0 To UBound(varGroups)
If UCase(varGroups(i)) = UCase(strGroup) Then
InGroup = True
Exit For
End If
Next i
End Function
Note: The code above is NOT my code, it was posted by VBSlammer in Thread705-666914. But I tried it out, and it works. Kudos to VBSlammer!
2) Create an event procedure in the On Open event of your form:
Code:
If InGroup("Admins") Then
Me.RecordSource = "qrySecLevel1"
Else
Me.RecordSource = "qrySecLevel2"
Me![UserOnly].Visible = False
End If
...where UserOnly is the name of the Yes/No checkbox on your form, presumably bound to a Yes/No field in your table. If you want users (that are not Admins) to be able to add records, since the checkbox field will be hidden, you should probably set the default value of your Yes/No field to True.
qrySecLevel1 is a query that includes all records from your table. qrySecLevel2 is a query that returns all records from your table where the Yes/No field is set to True.
3) Set up your security and assign appropriate permissions to your users/groups for the form and related data objects. This code assumes your administrators group is named "Admins" (that's an Access default).
HTH...
Ken S.