Solved Switchboard - disable right-click close menu. (1 Viewer)

Local time
Today, 05:48
Joined
Feb 28, 2023
Messages
628
I saw other threads asking this, but I didn't see a reply that looked like it would work.

I am using tabbed windows with tabs displayed. I have the close button set to No on the switchboard form. How do I disable the right-click close menu? (And how would I close the form if I wanted to after I disabled it?)

To clarify, I'm talking about these:

If I right-click on the tab:
1692281425073.png

Or I if right-click in the body of the form:
1692281760069.png

Thanks!
 

acmefinishing

New member
Local time
Today, 04:48
Joined
Oct 30, 2019
Messages
8
sm.png


On the form properties, set the "Shortcut Menu" to "No".

To make a close button, add a button to some place on the form and add in this code into VBA:

DoCmd.Close
 
Local time
Today, 05:48
Joined
Feb 28, 2023
Messages
628
That got rid of the second menu if I right-click in the body of the form, but I still have the first menu if I right-click on the tab ...
 
Local time
Today, 05:48
Joined
Feb 28, 2023
Messages
628
Found it!

File>Options>Current Database>Ribbon and Toolbar Options: Uncheck Allow Default Shortcut Menus:
1692283794054.png

It disables them for all tabs, but I'm okay with that. I don't see a way to set it on a per-tab basis, though.

Thanks!
 

isladogs

MVP / VIP
Local time
Today, 10:48
Joined
Jan 14, 2017
Messages
18,225
For info, you can also disable certain menu items in the navigation pane using
Code:
DoCmd.LockNavigationPane True

Set to False to restore normal functionality

For more info on ways of locking down your app, see
 
Local time
Today, 05:48
Joined
Feb 28, 2023
Messages
628
Navigation pane is hidden already (Well, on the development version of the FE, it is).

Great information on your website. I read it previously but haven't implemented all of it yet. Trying to grab the low-hanging fruit first!!!
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:48
Joined
Sep 21, 2011
Messages
14,301
Navigation pane is hidden already (Well, on the development version of the FE, it is).

Great information on your website. I read it previously but haven't implemented all of it yet. Trying to grab the low-hanging fruit first!!!
That is the last place you would want it I would have thought? :)
 
Local time
Today, 05:48
Joined
Feb 28, 2023
Messages
628
That is the last place you would want it I would have thought? :)
LOL!!! I see what you mean!!!

To be clear. I don't have a true "Admin" version of the front end.

The currently released version still has the Navigation Pane. The tables and queries are all hidden, but if anyone knows how to show hidden items, they can get to them.

The version I am readying for release now adds a switchboard and hides the navigation pane and the toolbars and a lot of other things.

There IS a button on the switchboard that allows ME to view the Navigation Pane or hide it, but only I see that b/c - well, it's good to be King.

For the most part, I try to keep my version of the FE as close to the released version of the FE b/c too often I've had to tell people "You just do this." "What, it doesn't work?" "Oh yeah, I forgot I disabled that for everyone else ..."
 
Local time
Today, 05:48
Joined
Feb 28, 2023
Messages
628
I found an interesting glitch and I don't have a workaround.

Form>Properties>Shortcut Menu>No disables the right click in the body of the current form only. It does not disable the right-click Close option on the form label in tabbed view.

So far so good. I want the right-click menu disabled on the switchboard. I want it enabled on the data forms b/c I am blocking datasheet view and it enables things like filtering on fields, etc.

File>Options>Allow Default Shortcut Menus DOES disable the right-click close menu on the tabs, but it disables a lot of other things also. For example:
  • It disables the right-click menu in the body of ALL forms, overriding the form properties setting.
  • It disables the right-click copy menu in a field, although CTRL-C still works.
  • If the Nav Pane is visible, it disables the menu options like "Hide in this view" and "Rename".
Ideally, I'm looking for a solution that will disable the right-click tab label menu for the switchboard only, although for all forms would work also.

If one doesn't exist, I may have to live with leaving the file Options setting enabled and telling our users "DO NOT close the switchboard form (even though you can).
 

acmefinishing

New member
Local time
Today, 04:48
Joined
Oct 30, 2019
Messages
8
I would probably add VBA on the Form_Close event of the switchboard form you don't want closed. Create a global variable for QuitSystem. Create a Quit System button that sets the global variable to true. On the Form_Close event, if the QuitSystem variable is not true, then run VBA to reopen the form they're trying to close.
 

acmefinishing

New member
Local time
Today, 04:48
Joined
Oct 30, 2019
Messages
8
Perhaps you should save the end-user file as a ACCDE file which is runtime only without access to the back-end of the application.
 
Local time
Today, 05:48
Joined
Feb 28, 2023
Messages
628
The end-user file is an .accde, but you still have the right-click menu options.

Can Reply ##10 be simplified?

I don't really want a quit system button - I'm fine with them clicking the red X or right-clicking the taskbar to close.

I tried doing this on the frm_Switchboard VBA:
Code:
Private Sub Form_Close()
    DoCmd.OpenForm "frmSwitchboard"
End Sub

And that didn't do AT ALL what I expected. i.e.
  • If I right-clicked on the switchboard tab and selected close, the form closed and DID NOT re-open. I had the nav pane open, so I could re-open it from there, but the end users won't have that option.
  • OTOH, if I clicked the redX to close Access, the form did TRY to re-open. The switchboard is the primary form, so all my startup code is on there, so I got a progress bar that the tables were loading and then eventually Access said it was not responding so I could say Restart and it closed. Workable, but far from elegant.
I like your approach in that if there were a way to cancel or re-open the form as soon as it was closed, that would work for me.
 

acmefinishing

New member
Local time
Today, 04:48
Joined
Oct 30, 2019
Messages
8
Another approach would be to have a hidden form that loads when the program is opened. It will cycle through on a timer that if it detects that the switch board form is closed, it will re-open it. I found this code online which I'm using to auto-close all forms on a database and log the user out if left idle for 30 minutes. Perhaps you should use it but in reverse. If the switch board form is closed, the hidden form will check every 15 or 30 seconds, re-open the switch board form.

learn . microsoft . com / en-us / office / vba / access / Concepts / Miscellaneous / detect-user-idle-time-or-inactivity
 

acmefinishing

New member
Local time
Today, 04:48
Joined
Oct 30, 2019
Messages
8
Another approach would be to have a hidden form that loads when the program is opened. It will cycle through on a timer that if it detects that the switch board form is closed, it will re-open it. I found this code online which I'm using to auto-close all forms on a database and log the user out if left idle for 30 minutes. Perhaps you should use it but in reverse. If the switch board form is closed, the hidden form will check every 15 or 30 seconds, re-open the switch board form.

learn . microsoft . com / en-us / office / vba / access / Concepts / Miscellaneous / detect-user-idle-time-or-inactivity
Just noticed a lot of this code will not apply to you. All that you would need to do is create a hidden form, and put it on a timer. When the timer runs, check if the switch board form is open, and if not, re-open it.
 
Local time
Today, 05:48
Joined
Feb 28, 2023
Messages
628
Not sure if it makes a difference, but I noticed the unload event has a cancel option.

What I need is a way to not close/unload the form if the user right-clicks and selects close but allow it to close otherwise.

I think reply 13 can probably work for me.

I have a hidden file that checks for a maintenance text file and if the file is present, it gives the user 3 minutes to finish up before it logs them out. I can just add code to that from to re-open the switchboard.

I think I set the timer for a minute, so it might take a minute before it re-loads, but I can live with that.

Will test and report back!

Thanks!
 

acmefinishing

New member
Local time
Today, 04:48
Joined
Oct 30, 2019
Messages
8
You can also try as you said with the Unload action.

Code:
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Err_Form_Unload

    If MsgBox("Closing the switch board screen will Quit the entire system.  Continue?", vbYesNo + vbQuestion + vbDefaultButton2, "Confirm Close") = True Then
        Application.Quit
    End If

Exit_Form_Unload:
    Exit Sub

Err_Form_Unload:
    MsgBox Err.Description
    Resume Exit_Form_Unload
End Sub
 
Local time
Today, 05:48
Joined
Feb 28, 2023
Messages
628
@acmefinishing - You're a lifesaver!!!

We were both overthinking and overcomplicating this.

I didn't want to quit the entire system if I closed the form and your solution does that. Also, from what I can see, your solution doesn't give another option - If they say yes, Access closes. If they say no, the switchboard still closes and without the nave pane, they have no way to get it back.

But I looked at other sections of my code and the solution was Really simple:
Code:
Private Sub Form_Unload(Cancel As Integer)
DoCmd.CancelEvent
End Sub

(I thought). They see the close button, but it doesn't do anything. (And they also can never close Access.

What would work is:
Code:
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Err_Form_Unload
    If MsgBox("Closing the switch board screen will Quit the entire system.  Continue?", vbYesNo + vbQuestion + vbDefaultButton2, "Confirm Close") = True Then
        Application.Quit
    Else
        DoCmd.CancelEvent
    End If

Exit_Form_Unload:
    Exit Sub

Err_Form_Unload:
    MsgBox Err.Description
    Resume Exit_Form_Unload
End Sub

Untested, but that should work. The problem I have with it is if they click the Red X, now they always have to say "Yes, I did mean to close the system.

The hidden form with the timer also works and I WILL use that:
Code:
Private Sub Form_Timer()
    If SysCmd(acSysCmdGetObjectState, acForm, "frmSwitchboard") = 0 Then
       DoCmd.OpenForm "frmSwitchboard"
    End If
End Sub

I have the default timer set for 60 seconds, so it might take a while, but that will teach them not to click the button also!!!
 

acmefinishing

New member
Local time
Today, 04:48
Joined
Oct 30, 2019
Messages
8
Yes, I noticed afterwards that the form would still close if said no to it. I seem to do it a lot where I post something that sounds like the solution and have to go back later and realize what I wrote may not work 100% lol.

Hopefully you were able to do what you wanted with it.
 
Local time
Today, 05:48
Joined
Feb 28, 2023
Messages
628
What I really want is similar to what I have in Reply #17 and what you have in Reply #10 - i.e.

If they right-click on the switchboard tab and click close, nothing happens b/c the DoCmd.CancelEvent catches it.

But if they click the red X on the Access Application, it should close with no message.

I just can't figure out how to do that, b/c I can't see how to set a flag from the Red X to run the switchboard unload event.

What I have is where if they close it the form re-opens, but it might take 60 seconds to start re-opening, but it's better than I started with.
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:48
Joined
Sep 21, 2011
Messages
14,301
Yes, I noticed afterwards that the form would still close if said no to it. I seem to do it a lot where I post something that sounds like the solution and have to go back later and realize what I wrote may not work 100% lol.

Hopefully you were able to do what you wanted with it.
I think you should be testing for vbYes, not True?
 

Users who are viewing this thread

Top Bottom