UnLoad a ribbon on logout (1 Viewer)

AliyuKatsina

Registered User.
Local time
Today, 09:20
Joined
Dec 31, 2009
Messages
73
I have a distributed FE with getVisible callback function on the most of the ribbon controls. So depending on user permission, some controls are visible to some users and not visible to others.
The ribbon is attached to the main form that stays open. I created a logout function that closes the main form and opens the login form.
My problem is though I close the main form, the ribbon stays. so if a user with permission on control A logs out, if another user without permission on that control logs on he can access that function.
What I want is to completely unload the ribbon when somebody logs out.
 

ypma

Registered User.
Local time
Today, 08:20
Joined
Apr 13, 2012
Messages
643
Could you not use ; on the log on form current action event

#if not permission your code for permission then
DoCmd.ShowToolbar "Ribbon", acToolbarNo

end If #

Hope this of use to you.

Regards Ypam
 

isladogs

MVP / VIP
Local time
Today, 08:20
Joined
Jan 14, 2017
Messages
18,207
This is what I use in the Form_Load event of the login form:

Code:
...

  [COLOR="Green"]'Delete existing start up properties[/COLOR]
    DeleteStartupProps "AllowFullMenus"
    DeleteStartupProps "StartUpShowStatusBar"
    DeleteStartupProps "AllowBuiltInToolbars"
    DeleteStartupProps "AllowShortcutMenus"
    DeleteStartupProps "AllowToolbarChanges"
    DeleteStartupProps "AllowSpecialKeys"
    DeleteStartupProps "StartUpShowDBWindow"
    DeleteStartupProps "AllowBypassKey"

    [COLOR="green"]'By default, set all start up properties to False[/COLOR]
    StartUpProps "AllowBypassKey", False, True
    StartUpProps "AllowFullMenus", False, True
    StartUpProps "StartUpShowStatusBar", False, True
    StartUpProps "AllowBuiltInToolbars", False, True
    StartUpProps "AllowShortcutMenus", False, True
    StartUpProps "AllowToolbarChanges", False, True
    StartUpProps "AllowSpecialKeys", False, True
    StartUpProps "StartUpShowDBWindow", False, True
    
    [COLOR="DarkRed"]HideRibbon 
      HideNavigationPane [/COLOR]
...

Then as part of the code after logging in with user name / password, I have:

Code:
...
 If [COLOR="darkred"]GetAdminManagerStatus[/COLOR] = True Then
            Application.Echo False
            
            StartUpProps "AllowBypassKey", True, True
           [COLOR="green"] 'StartUpProps "StartUpShowDBWindow", True, True - Removed and added below to hide DB window until admin logs in. this
                                                            'will not make it as obvious if forget to open and close before release.[/COLOR]
         [COLOR="green"] '  DoCmd.SelectObject acTable, , True[/COLOR]
            StartUpProps "AllowFullMenus", True, True
            StartUpProps "StartUpShowStatusBar", True, True
            StartUpProps "AllowBuiltInToolbars", True, True
            StartUpProps "AllowShortcutMenus", True, True
            StartUpProps "AllowToolbarChanges", True, True
            StartUpProps "AllowSpecialKeys", True, True
            
            [COLOR="darkred"]ShowRibbon
             ShowNavigationPane[/COLOR]
            
            DoEvents
            Application.Echo True
        End If

....


The functions shown in RED are:
a) GetAdminManagerStatus - returns True/False
- this checks whether the logged in user has admin status to see ribbon etc

b)
Code:
Public Function HideRibbon()
     DoCmd.ShowToolbar "Ribbon", acToolbarNo
End Function

c)
Code:
Public Function ShowRibbon()
     DoCmd.ShowToolbar "Ribbon", acToolbarYes
End Function

d)
Code:
Public Function ShowNavigationPane() 

'only available for AdminManagers
If GetAdminManagerStatus = True Then
    DoCmd.SelectObject acTable, , True
End If
        
End Function

e)
Code:
Public Function HideNavigationPane()

'only for AdminManagers
If GetAdminManagerStatus = True Then
    DoCmd.SelectObject acForm, , True
    DoCmd.SelectObject acQuery, , True
    DoCmd.SelectObject acReport, , True
    DoCmd.SelectObject acMacro, , True
    DoCmd.SelectObject acModule, , True
    DoCmd.SelectObject acTable, , True
    DoCmd.NavigateTo "acNavigationCategoryObjectType" 
    DoCmd.RunCommand acCmdWindowHide
End If

End Function


Use / adapt as suits your circumstances.
I've removed my customised error handling but suggest you add your own
 

AliyuKatsina

Registered User.
Local time
Today, 09:20
Joined
Dec 31, 2009
Messages
73
Thanks Ridders and ypma for your suggessions. Ridders I learned alot from your codes. Thanks a lot.
However I created a logout function that creates and execute a batch file that restarts the front end. And it solved my problem.

Public FEPath As String
Option Compare Database

Sub LogOut()
Dim strFilePath As String

FEPath = CurrentDb.NAME

strFilePath = CurrentProject.Path & "\ReStartFE.cmd"

If Dir(strFilePath) <> "" Then
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
fs.DeleteFile (strFilePath)
Set fs = Nothing
End If

ReStartFE

End Sub

Public Sub ReStartFE()
Dim TestFile As String
Dim strRestart As String

' sets the file name of the batch file to create
TestFile = CurrentProject.Path & "\ReStartFE.cmd"
' sets the restart file name
strRestart = """" & FEPath & """"
' creates the batch file
Open TestFile For Output As #1
Print #1, "Echo Off"
Print #1, ""
Print #1, "ping 1.1.1.1 -n 1 -w 2000"
Print #1, ""
Print #1, "START /I " & """MSAccess.exe"" " & strRestart
Close #1
' runs the batch file
Shell TestFile

'closes the current version and runs the batch file
DoCmd.Quit



End Sub
 

Users who are viewing this thread

Top Bottom