gojets1721
Registered User.
- Local time
- Today, 15:09
- 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:
And here is the command:
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