Darken background when Msgbox appears

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:49
Joined
May 7, 2009
Messages
20,641
It is sometimes desirable to darken the background when a Msgbox appears
so as to catch the attention to the presented message or warning.

This is not new, but just wanted to share if it can be of use to you.
The code can be used on older Ms Access.

Open frmDemo on the attached.
 

Attachments

i agree that the blur is not pleasant to the eyes.
but you may try to increase the blur radius, say 20 instead of 5, and you will see it is more pleasant.
blur.jpg
 
It is sometimes desirable to darken the background when a Msgbox appears
so as to catch the attention to the presented message or warning.

This is not new, but just wanted to share if it can be of use to you.
The code can be used on older Ms Access.

Open frmDemo on the attached.

With Fade In/Out Timer...
 

Attachments

The fade feature is a nice touch, Colin did something very similar to this in his AttentionSeekingDB a few years ago. I always meant to incorporate it but never got around to it. I took yours and Arnel's version and adapted it to my project for all my pop-up forms. The clients are going to love it, I sure as hell do!
 
I wanted to take this little further and make it so that it would work for forms, reports and MsgBoxs. It works great for forms and Msgboxs just fine because they are Modal. Reports open and the background dims, but it does not pause the code: The FadeOutOverlay runs after the report opens. I even tried making the report Modal, but it still does not work.

Code:
Public Sub OverlayedObject(strType As String, strTarget As String= "", Optional strWhere As String = "", Optional strMsg As String = "")
    On Error GoTo Err_Handler

' Dim background
    FadeInOverlay 180, 20

    Select Case strType
        Case "form"
            If Len(strWhere) > 0 Then
                DoCmd.OpenForm strTarget, , , strWhere, , acDialog
            Else
                DoCmd.OpenForm strTarget, , , , , acDialog
            End If
        Case "report"
            If Len(strWhere) > 0 Then
                DoCmd.OpenReport strTarget, , , strWhere, , acDialog
            Else
                DoCmd.OpenReport strTarget, , , , , acDialog
            End If
        Case "msgbox"
            MsgBox strMsg, vbInformation, strTarget
        Case Else
            'MsgBox "Unknown type: " & strType, vbExclamation
    End Select

Exit_Handler:
    ' Restore background
    FadeOutOverlay 180, 20
    Exit Sub

Err_Handler:
    MsgBox "Error in OverlayedObject: " & Err.Description, vbCritical
    Resume Exit_Handler
End Sub

Any ideas?
 
Last edited:
I wanted to take this little further and make it so that it would work for forms, reports and MsgBoxs. It works great for forms and Msgboxs just fine because they are Modal. Reports open and the background dims, but it does not pause the code: The FadeOutOverlay runs after the report opens. I even tried making the report Modal, but it still does not work.

Code:
Public Sub OverlayedObject(strType As String, Optional strTarget As String= "", Optional strWhere As String = "", Optional strMsg As String = "")
    On Error GoTo Err_Handler

' Dim background
    FadeInOverlay 180, 20

    Select Case strType
        Case "form"
            If Len(strWhere) > 0 Then
                DoCmd.OpenForm strTarget, , , strWhere, , acDialog
            Else
                DoCmd.OpenForm strTarget, , , , , acDialog
            End If
        Case "report"
            If Len(strWhere) > 0 Then
                DoCmd.OpenReport strTarget, , , strWhere, , acDialog
            Else
                DoCmd.OpenReport strTarget, , , , , acDialog
            End If
        Case "msgbox"
            MsgBox strMsg, vbInformation, strTarget
        Case Else
            'MsgBox "Unknown type: " & strType, vbExclamation
    End Select

Exit_Handler:
    ' Restore background
    FadeOutOverlay 180, 20
    Exit Sub

Err_Handler:
    MsgBox "Error in OverlayedObject: " & Err.Description, vbCritical
    Resume Exit_Handler
End Sub

Any ideas?

This is a known behavior in Access: reports open asynchronously and don’t block code execution, even if you set them as modal. Unlike forms and MsgBoxs, reports don’t have a built-in modal mode that pauses VBA execution.

To handle this, you typically need a workaround such as:

Using a timer or loop to detect when the report is closed before running FadeOutOverlay.
Opening the report in a way that forces code to wait, such as opening a form that mimics the report or using API calls to detect window focus.
Or redesigning the user flow so the overlay fades out on a user action or event rather than immediately after opening the report.


Out in field, will take a look when i get back later……

Using the Timer/Loop Aproach……

Add the following Sub:-


Code:
' InView
' NEW FUNCTION TO OPEN REPORT MODALLY WITH OVERLAY
Public Sub OpenReportModalWithOverlay(reportName As String, Optional finalTransparency As Byte = 180, Optional stepDelay As Long = 5) ' Show the overlay with fade-in effect FadeInOverlay finalTransparency, stepDelay

    'Open Report Example
    DoCmd.OpenReport reportName, acViewPreview

    ' Wait until the report is closed before fading out overlay
    Do While SysCmd(acSysCmdGetObjectState, acReport, reportName) <> 0
        DoEvents
        Sleep 100
    Loop

    ' Fade out the overlay after report is closed
    FadeOutOverlay finalTransparency, stepDelay

End Sub

That should work..

Call:
OpenReportModalWithOverlay "YourReportNameHere"

You will likely need to modify the Fade Out Loop:-


Code:
For i = startAlpha To 0 Step -10
    If CurrentProject.AllForms("frmOverlay").IsLoaded Then
        Forms("frmOverlay").SetTransparency CByte(i)
        DoEvents         ' Allow UI updates
        Sleep stepDelay  ' Pause between steps
    Else
        Exit For
    End If
Next i
 
Last edited:
At the appropriate place, you may need to add

hwnd = reports(strtarget).hwnd
do while iswindowenabled(hwnd)
doevents
loop

You still need to declare the API for iswindowenabled.
 
This is a known behavior in Access: reports open asynchronously and don’t block code execution, even if you set them as modal. Unlike forms and MsgBoxs, reports don’t have a built-in modal mode that pauses VBA execution.
Thanks, I found that out the hard way. The work around I came up with is:

Code:
 Case "report"
            ' Reports do not halt code execution - go figure
            DoCmd.OpenReport strTarget, acViewPreview, , strWhere
            ' Pause until report closes
            Do While CurrentProject.AllReports(strTarget).IsLoaded
                DoEvents
            Loop

I thought it was a little "clunky" so I decided to ask those who are smarter than me...
 
Last edited:
OMG, how thick am I?!? All that needs to be done is:

Code:
FadeInOverlay 180, 20
    DoCmd... 'open your form, report
    ' or
    MsgBox...
FadeOutOverlay 180, 20

No need for the complicated OverLayedWhatever() sub. How long were you guys going to let me show my DumbAssery before you stepped in??!?! Probably still going to need to loop thingy for the reports, but still much easier...good Lord...
 
OMG, how thick am I?!? All that needs to be done is:

Code:
FadeInOverlay 180, 20
    DoCmd... 'open your form, report
    ' or
    MsgBox...
FadeOutOverlay 180, 20

No need for the complicated OverLayedWhatever() sub. How long were you guys going to let me show my DumbAssery before you stepped in??!?! Probably still going to need to loop thingy for the reports, but still much easier...good Lord...

lol, i was not sure what you were asking…… Like this?
 

Attachments

I get the same. :unsure:

I recently uploaded a ZIP file containing a single video, but it was flagged as containing a virus. I’ve scanned the file using VirusTotal and other reputable tools, and all results confirm it’s completely clean — not a single engine flagged it as malicious.

The ZIP contains only one .mp4 file, with no scripts, executables, or hidden content. This appears to be a false positive, likely triggered by automated heuristics or the packaging format.

What’s more concerning is that when I attempt to download the file from the site, I receive the same virus warning — suggesting the issue may lie with the hosting platform itself. I’m confident the original upload was clean, and it’s possible the file is being flagged or altered post-upload.

Having worked in cyber security for six years with the Ministry of Defence, I take file hygiene seriously. I’d recommend the moderators investigate the hosting environment to rule out any unintended interference or misclassification. Happy to assist further if needed.
 
I was able to DL it on my cell with no issues - sounds like it may be a disconnect between the hosting platform and the Windows OS.
 

Users who are viewing this thread

Back
Top Bottom