Change custom ribbon with password (1 Viewer)

ITguy1981

Registered User.
Local time
Today, 05:41
Joined
Aug 24, 2011
Messages
137
I'm looking for a way to change the custom ribbon by clicking a button on a ribbon and entering a password. Right now my database has two ribbons. One labeled developers and one labeled users. Basically, the users ribbon hides all the ribbons, but the one custom ribbon. I would like to click a button on my custom ribbon that would prompt for a password. If the correct password is entered it would change the ribbon to "developers" and restart the database to load the correct ribbon.
 

isladogs

MVP / VIP
Local time
Today, 10:41
Joined
Jan 14, 2017
Messages
18,213
Do your users log in to the db?
If so you could assign the developer ribbon to specified users using start up conditions and avoid the need for a separate password.
It would also be more secure
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:41
Joined
May 7, 2009
Messages
19,230
My suggestion is to use 1 ribbon and disabke or hide rubbon controls if the user is not a developer
 

ITguy1981

Registered User.
Local time
Today, 05:41
Joined
Aug 24, 2011
Messages
137
Currently, I do not have users logging in. In this case it would probably be easier to have an admin password option to unhide ribbon controls. Any help with this would be appreciated as I am new to working with ribbons.
 

Minty

AWF VIP
Local time
Today, 10:41
Joined
Jul 26, 2013
Messages
10,371
If you are on a domain you could simply un-hide the dev ribbon if you are the current windows user?
 

isladogs

MVP / VIP
Local time
Today, 10:41
Joined
Jan 14, 2017
Messages
18,213
OK - this would definitely be easier (and better) if users logged in.

However, the following code may be useful.
Copy it to a new module

Code:
Option Compare Database
Option Explicit

Public Function HideRibbon()
    'could run at startup using Autoexec
    'however this also hides the QAT which makes printing reports tricky
     DoCmd.ShowToolbar "Ribbon", acToolbarNo
   '  DoCmd.ShowToolbar "PrintReport", acToolbarYes
End Function

Public Function ShowRibbon()
    'use when opening a report to display print preview ribbon
     DoCmd.ShowToolbar "Ribbon", acToolbarYes
End Function

Public Function ToggleRibbonState()

'hide ribbon if visible & vice versa
    CommandBars.ExecuteMso "MinimizeRibbon"
End Function

Public Function IsRibbonMinimized() As Boolean
    'Result: 0=normal (maximized), -1=autohide (minimized)

    IsRibbonMinimized = (CommandBars("Ribbon").Controls(1).Height < 100)
   ' Debug.Print IsRibbonMinimized
End Function

Add the function HideRibbon to an Autoexec macro so it runs at startup

Add code so developers can enter the password using an input box (preferably a masked input box - I have code for this also).
If the password is correct, run the ShowRibbon function

Are your users able to view the navigation pane or the VBE editor?
I suggest the answer should be NO to both
If you are unaware how to do both of these, get back to me ...

One problem you have is that the password has to be stored somewhere in the database. You could use one of these methods:
a) in a table - if so it needs to be encrypted!
b) in a module - defined as a Const - ideally encrypted

Encryption is a whole separate area
You see how its getting more complicated ....

Also if users run reports, they will need to see the Print Preview ribbon.
However you don't want it to stay visible after the report is closed

Add code like this to each report to do this:

Code:
Private Sub Report_Close()

On Error GoTo Err_Handler

    'Minimize ribbon
    If IsRibbonMinimized = False Then ToggleRibbonState
    
Exit_Handler:
    Exit Sub
    
Err_Handler:
    MsgBox "Error " & Err.Number & " in Report_Close procedure : " & Err.Description, vbOKOnly + vbCritical
    Resume Exit_Handler

    
End Sub

Private Sub Report_Load()

On Error GoTo Err_Handler
  
    'Show & maximize ribbon
    ShowRibbon
    If IsRibbonMinimized = True Then ToggleRibbonState

Exit_Handler:
    Exit Sub
    
Err_Handler:
    MsgBox "Error " & Err.Number & " in Report_Load procedure : " & Err.Description, vbOKOnly + vbCritical
    Resume Exit_Handler

End Sub

At the end of all this, I'll just repeat that it would be much better if users logged in
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:41
Joined
May 7, 2009
Messages
19,230
this is a customized dynamic ribbon
sample.

hope you get the idea.
 

Attachments

  • DynamicRibbon.zip
    33.1 KB · Views: 94

ITguy1981

Registered User.
Local time
Today, 05:41
Joined
Aug 24, 2011
Messages
137
Thanks Ridders. The password could just be in a table and I really wouldn't even need that encrypted. I plan on hiding editing options and tables along with disabling the bypass at startup. Mostly I just want easy access for myself to be able to edit the database and disable it so users can't accidentally mess it up. I'm not worried about them intentionally trying to change it.
 

ITguy1981

Registered User.
Local time
Today, 05:41
Joined
Aug 24, 2011
Messages
137
Thanks Arnel. I think I may try your option first as I just need a way to change the ribbon with input data. In my case I'll just use password in place of the username.
 

isladogs

MVP / VIP
Local time
Today, 10:41
Joined
Jan 14, 2017
Messages
18,213
Reading your reply in post #8, I think you're over complicating this.
Use code to hide the ribbon and navigation pane etc at start up.
Save as ACCDE and distribute that for all users.
Keep the ACCDB file for you to use as a developer.

That's it.
Job done.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:41
Joined
Feb 28, 2001
Messages
27,167
ITGuy - if you are on a domain, you have already identified yourself and used a password to do it! Have the users in a USERS table, for sure, but don't re-invent the wheel. Just get the user's login name via Environ( "Username" ) and move to the tougher problems.

I'm sort of "seconding" Minty's opinion here.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:41
Joined
May 7, 2009
Messages
19,230
If you are the User, would you like
to work on a db without ribbon or anything.

It's boring and look stupid.

Anyway, he said he is currently
working on the ribbon, so I gave
him something to work on.
 

ITguy1981

Registered User.
Local time
Today, 05:41
Joined
Aug 24, 2011
Messages
137
Thank you for all of the replies. I'll post back when I get a chance to work on the database more. Hopefully, I can later today or tomorrow.
 

isladogs

MVP / VIP
Local time
Today, 10:41
Joined
Jan 14, 2017
Messages
18,213
If you are the User, would you like
to work on a db without ribbon or anything.

It's boring and look stupid.

Anyway, he said he is currently
working on the ribbon, so I gave
him something to work on.

Arnel

You make many excellent contributions and indeed have done so on this thread. You provided a solution and that's fine.

However I have to take issue with the above comment.

The important issue is whether the database is completely functional.
If you want it to be more secure in a multiuser environment, then removing the ribbon is one step towards achieving that.
If the database is well designed, ribbons and toolbars aren't necessarily required.

I have been distributing databases for over 10 years with no ribbon for standard users.
The only exception is reinstating print preview ribbon whilst reports are open.

This doesn't make the databases 'boring or stupid' as you put it.
Obviously program admins and developers have additional rights including ribbons, full menus and navigation pane ... because they need them.
Standard users don't
 

ITguy1981

Registered User.
Local time
Today, 05:41
Joined
Aug 24, 2011
Messages
137
So after doing a lot of research I've learned that you can't change the main ribbon without reloading the database and I would even be okay with that, but there doesn't seem to be any way through VB to change the default on load ribbon that you would normally set through the database options. I'm not familiar with databases at all as far as coding goes and I know at this point the structure itself isn't ideal. I've been tossing a few ideas around. I think it would be best to have a default ribbon and then hide an admin tab on the ribbon instead. I have a small table with two users and a yes/no box admin and a password field. I have an admin button on my ribbon that opens a login form. How can I have it hide or unhide the tab based off the username and password along with the yes/no option for admin as a user?
 

Users who are viewing this thread

Top Bottom