Flash a Window’s Titlebar or Icon
Problem
With so many windows open in your Access applications, it can be difficult to force your user’s attention to a specific form. Is there a way to make the titlebar flash so that a form really stands out?
Solution
Windows supplies a simple API call, FlashWindow, that allows you to flash the titlebar of a form or its icon (if it’s iconized) on and off. This solution will demonstrate how you can use the FlashWindow API call to draw attention to a specific form.
To include this functionality in your own applications, follow these steps:
Add this API declaration to your code in the declarations section of the form’s module:
Private Declare Function FlashWindow Lib "User32" _ (ByVal hWnd As Long, ByVal lngInvert As Long) As Long
In our example, the declaration is in the module for frmControlFlash.
Create a module-level variable (
mhWndin our example) to hold the flashed form’s window handle:Dim mhWnd As Long
Create a procedure attached to your controlling form’s Timer event, causing the form to flash:
Private Sub Form_Timer( ) Static fFlash As Boolean FlashWindow mhWnd, fFlash fFlash = Not fFlash End Sub
To turn the flashing on and off, add code like this to react to some event (on the sample form, you trigger the code in reaction to the Click event of the Flash button):
Private Sub cmdFlash_Click( ) Dim strCaption As String Dim ctl As Control Set ctl = Me!cmdFlash strCaption = ctl.Caption If strCaption = "Flash" Then ' If the form's already open, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access