Need help with show/hide application window code (1 Viewer)

gojets1721

Registered User.
Local time
Today, 02:23
Joined
Jun 11, 2019
Messages
430
I found some code online to show/hide the application window behind my form. Essentially, it boots up with the application window hidden, and then I have a command that, when pressed, shows the application window, the ribbon, and the nav bar.

It works except the ribbon at the top is shown but not enabled. All the buttons, etc. are disabled and unable to be pressed.

I am not fluent enough with the code to figure out what is causing that and so I was looking for some guidance.

Here is the module:
Code:
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3

'###############################################
#If VBA7 Then
    Private Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
#ElseIf Win64 Then 'need datatype LongPtr
    Private Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As LongPtr, ByVal nCmdShow As LongPtr) As LongPtr
#Else '32-bit Office
    Private Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
#End If
'###############################################

Function SetAccessWindow(nCmdShow As Long)

    'Usage Examples
    'Maximize window:
    ' ?SetAccessWindow(SW_SHOWMAXIMIZED)
    'Minimize window:
    ' ?SetAccessWindow(SW_SHOWMINIMIZED)
    'Hide window:
    ' ?SetAccessWindow(SW_HIDE)
    'Normal window:
    ' ?SetAccessWindow(SW_SHOWNORMAL)
    
    Dim loX As Long
   ' Dim loForm As Form
    On Error Resume Next
    
    loX = apiShowWindow(hWndAccessApp, nCmdShow)
    SetAccessWindow = (loX <> 0)

End Function

And here is the command:
Code:
Dim blnShowWindow As Boolean

Private Sub btnShowHideApplicationWindow_Click()

On Error GoTo Err_Handler

     If Me.btnShowHideApplicationWindow.Caption = "Show Application Window" Then
        
        SetAccessWindow (SW_SHOWMAXIMIZED)
        blnShowWindow = True
        Me.btnShowHideApplicationWindow.Caption = "Hide Application Window"
        
        DoEvents
    Else
        'close & reopen form
        Application.Echo False
        DoCmd.Close acForm, Me.Name
        DoCmd.OpenForm "frmSettings"
      '  SetAccessWindow (SW_SHOWMINIMIZED)
        Application.Echo True
        
        blnShowWindow = False
    End If
    
    
Exit_Handler:
    Exit Sub

Err_Handler:

    MsgBox "Error " & Err.Number & Err.Description
    Resume Exit_Handler

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:23
Joined
Oct 29, 2018
Messages
21,473
Can you post a screenshot?
 

gojets1721

Registered User.
Local time
Today, 02:23
Joined
Jun 11, 2019
Messages
430
Sure, but of what exactly? The ribbon? It looks like a normal ribbon. It's just behaving like its not even there though when I try to press a button. Nothing happens. The buttons don't even highlight
 

gojets1721

Registered User.
Local time
Today, 02:23
Joined
Jun 11, 2019
Messages
430
Ribbon below. A lot are greyed out and the ones that aren't & the tabs don't do anything when pressed
 

Attachments

  • Capture.PNG
    Capture.PNG
    18 KB · Views: 87

theDBguy

I’m here to help
Staff member
Local time
Today, 02:23
Joined
Oct 29, 2018
Messages
21,473
Sure, but of what exactly? The ribbon? It looks like a normal ribbon. It's just behaving like its not even there though when I try to press a button. Nothing happens. The buttons don't even highlight
I was hoping of the entire screen. Some ribbon controls are context sensitive and are supposed to be disabled when they don't apply to the current context.
 

gojets1721

Registered User.
Local time
Today, 02:23
Joined
Jun 11, 2019
Messages
430
There's nothing else to show though. The only other thing would be the Nav Pane, but that's working fine
 

isladogs

MVP / VIP
Local time
Today, 10:23
Joined
Jan 14, 2017
Messages
18,224
It would help if you gave a link to the code you downloaded.
It looks like a very old version of my code but I haven't used 3-part conditional compilation like that for several years.
There is newer code available at e.g.
 

gojets1721

Registered User.
Local time
Today, 02:23
Joined
Jun 11, 2019
Messages
430
It would help if you gave a link to the code you downloaded.
It looks like a very old version of my code but I haven't used 3-part conditional compilation like that for several years.
There is newer code available at e.g.
Thank you so much. This is extremely helpful.

If all I wanted was the 'design' button that you have on the top of the start form, how would you suggest I limit the code to that? All I'm looking for is a single button that shows the app window, the ribbon, the nav pane and drops the form to design mode
 

isladogs

MVP / VIP
Local time
Today, 10:23
Joined
Jan 14, 2017
Messages
18,224
That's exactly what that button does in my example app. Look at the code provided.
 

gojets1721

Registered User.
Local time
Today, 02:23
Joined
Jun 11, 2019
Messages
430
That's exactly what that button does in my example app. Look at the code provided.
Okay thanks. One last question...what code in your DB is restricting the user from being able to right click and enter design mode?
 

isladogs

MVP / VIP
Local time
Today, 10:23
Joined
Jan 14, 2017
Messages
18,224
The form's shortcut menu property is set to No to prevent right clicking
 

gojets1721

Registered User.
Local time
Today, 02:23
Joined
Jun 11, 2019
Messages
430
The form's shortcut menu property is set to No to prevent right clicking
Thank you. Your newer version has worked great.

One last (and somewhat specific question) regarding the start form and dual monitors. Whenever I open up forms from the start form, they open up on the monitor where the application window is (but the application is hidden) and not on the monitor where the start form is.

Any suggestions on if that can be changed? Ideally a new form would open up on the same monitor as the start form.
 

isladogs

MVP / VIP
Local time
Today, 10:23
Joined
Jan 14, 2017
Messages
18,224
Standard forms always open on the same screen as the application window.
However, popup forms are independent of the application window and always open on the same monitor as they were last saved.

So, for dual monitors you will need to open the forms in design view, drag to your preferred monitor and save
 

Users who are viewing this thread

Top Bottom