How do I force the Windows taskbar to always be on top?

lordrp

New member
Local time
Today, 12:56
Joined
Apr 14, 2014
Messages
3
I write Access 2010 apps in VBA that require no knowledge of Microsoft Access on the part of the user. My forms contain all the necessary controls to use the program without relying on any of the Microsoft Access toolbars. I call this "de-Microsofting" the app. When I prepare the .accdb program to create a .accde app, I uncheck every checkbox (Options/Current Database) except "Compact on Close". This works well, but it also hides the Windows taskbar at the bottom of the screen. Some of my users need to be able to jump from my app to others (e.g., Excel) and back without having to exit my app. How can I force the Windows taxkbar to always be on top using VBA or, possibly, some setting?
 
Have you ask your user about permission to change their computer settings using code, (it is a Task-bar property)?
If it were my computer, I would not allow it!
 
Hi JHB. I never thought of it that way. My problem is not so much about the user's own settings, but it's an Access .accde app obliterating the Windows taskbar. Users with dual monitors have no problem - they just move my app to the other monitor. So let me alter my question. How can I do something in VBA to force the Windows taskbar to always be on top while my app is running, and then reverse whatever I've done on exiting the app? Note: I'm running in a military network where setting the taskbar to always be on top is NOT in the users property selection list. Perhaps there's a VBA function that makes my app always be in the back!
 
Try the below code, create a form, place 2 buttons in it, call them Command1 and Command2, set the on click event, and put the code in the form's module..

Code:
Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
 
Private Declare Function SetWindowPos Lib "user32" _
(ByVal handleW1 As Long, _
ByVal handleW1InsertWhere As Long, ByVal w As Long, _
ByVal x As Long, ByVal y As Long, ByVal z As Long, _
ByVal wFlags As Long) As Long
 
Const TOGGLE_HIDEWINDOW = &H80
Const TOGGLE_UNHIDEWINDOW = &H40
Const TOGGLE_AUTOHIDE = &H1
Const TOGGLE_ALWAYSONTOP = &H2


Private Sub Command0_Click()
  Call UnhideTaskbar
End Sub

Private Sub Command1_Click()
  Call HideTaskbar
End Sub
 
Function HideTaskbar()
    handleW1 = FindWindowA("Shell_traywnd", "")
    Call SetWindowPos(handleW1, 0, 0, 0, 0, 0, TOGGLE_HIDEWINDOW)
End Function
 
Function UnhideTaskbar()
    handleW1 = FindWindowA("Shell_traywnd", "")
    Call SetWindowPos(handleW1, 0, 0, 0, 0, 0, TOGGLE_UNHIDEWINDOW)
    Call SetWindowPos(handleW1, 0, 0, 0, 0, 0, TOGGLE_ALWAYSONTOP)
End Function
 
:) Thanks for the code, JHB. This did the trick. I did run into a little trouble at first by pasting the entire block of code at the end of an existing form's VBA code. I got a compile error saying "Only comments may appear after End Sub, End Function, or End Property." The solution to this was to place the following portion of your code at the very top of the module before any executable code. After that, joy!

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function SetWindowPos Lib "user32" _
(ByVal handleW1 As Long, _
ByVal handleW1InsertWhere As Long, ByVal w As Long, _
ByVal x As Long, ByVal y As Long, ByVal z As Long, _
ByVal wFlags As Long) As Long

Const TOGGLE_HIDEWINDOW = &H80
Const TOGGLE_UNHIDEWINDOW = &H40
Const TOGGLE_AUTOHIDE = &H1
Const TOGGLE_ALWAYSONTOP = &H2
 

Users who are viewing this thread

Back
Top Bottom