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

Database window only for Admins 2

Status
Not open for further replies.

BrenoAguiar

IS-IT--Management
Feb 8, 2005
81
US
Is there a way to lock the "database window" in access, only for Admins?
Or is there a way to use a form and a command button that would open that Window using the "acCmd...." ?
I know about the special keys, but I'd like to block that too.

Thanks for the help.

Breno
 
You can go to the Menu ==> Tools ==> Startup and uncheck all the boxes that the Database Window does not show up when the startup form opens.

You can hold down the Shift key before starting up access and then the Database window will appear again
 
Thanks.. that will work.

But can that work the same way for the toolbars?
Also, is there a way to open that window through a command button?
 
You should think about using the "USER LEVEL SECURITY" . Read more at Microsoft & [link here][/url] Also FancyPrairie Thread181-1026600


________________________________________
Zameer Abdulla
Visit Me
Hold your child's hand every chance you get.
A time will come when he or she won't let you.
 
This will show the hidden database window if permissions allow:
[tt]
DoCmd.SelectObject acTable, "", True
[/tt]

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Thanks Again VBSlammer! Thats what I needed. I assume there should be one for the "tools/security" too ah?

Breno
 
Zameer,
I have already the DB set up on a USER LEVEL mode. But I could not find a way to prevent the user to open the DB window. But as an ADMIN, I would like to open it. Maybe there is a way to show tools and db window only if you login as admin.
 
You can find out if a user is in the Admins group:
[tt]
If IsAdmin() Then
[green]'allow task[/green]
End If
[/tt]
Code:
Function IsAdmin(Optional ByVal strUser As String) As Boolean
  Dim wrk As Workspace
  Dim usr As User
  Dim grp As Group
  
  On Error Resume Next
  
  Set wrk = DBEngine.Workspaces(0)
  
  If Len(strUser) > 0 Then
    Set usr = wrk.Users(strUser)
  Else
    Set usr = wrk.Users(Application.CurrentUser)
  End If
  
  For Each grp In usr.Groups
    If grp.Name = "Admins" Then
      IsAdmin = True
      Exit For
    End If
  Next grp
End Function
To launch the security dialogs:
[tt]
RunCommand acCmdUserAndGroupAccounts
RunCommand acCmdUserAndGroupPermissions
[/tt]

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
GREAT!

Thanks again VBSlammer.. Thats right on the spot!

have a star..
 
More general you can check to which group a user belongs:

Code:
Public Function BelongsToGroup(strUserName As String, strGroupName As String) As Boolean
' This function will return TRUE IF the current user is a member of the group supplied in the arguments _

Dim conn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim i, k As Integer
Dim ConnStr As String

On Error GoTo Error
BelongsToGroup = False
MdwLocation = "Jet OLEDB:System database=" & SysCmd(acSysCmdGetWorkgroupFile)
ConnStr = "data source=" & CurrentDb.name & ";" & MdwLocation & ";user id=db_admin;Password='YOURdb_adminPASSWORD'"

With conn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = ConnStr
    .Open
End With

Set cat.ActiveConnection = conn
With cat

For i = 0 To (.Users(strUserName).Groups.Count - 1) ' Check all groups of this username
Debug.Print "gebruiker: " & strUserName & " behoort tot de groep: " & .Users(strUserName).Groups(i)
    If .Users(strUserName).Groups(i) = strGroupName Then
        BelongsToGroup = True
    End If
Next i
End With

conn.Close
Exit Function

Error:
If Err.Number = 3265 Then
    Debug.Print "user: " & strUserName & " is not a user of this db."
    Exit Function
Else
    DoCmd.SetWarnings True
    MsgBox Err.Description & " " & Err.Number
End If

conn.Close
End Function

As you see in the connectionstring i use a admin account & password, but you can probably modify your db a bit (or the connstr) to suit your needs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top