Forum Discussion
Msaccess Enhanced Message Box - Office update issue
This Code has been working for 10 years.
Then, an Office update causes multiple instances of the form to remain open. If I revert to 16.0.17531.20120 all is well.
This creates multiple instances:
' Create the MessageBox
Dim F As New Form_frmEnhancedMessageBoxFormDialog
This is supposed to close the form.
' cleanup
Set F = Nothing
Every time a message is displayed, a new instance of the form is opened, and after the user responds, it is hidden. The cleanup does not work. I tried unloading and closing the form but they are not part of the forms collection that can be referenced.
I waited to see if a Microsoft update would fix the problem, but so far, no luck.
Has anyone experienced the same issue?
The code came from here: https://datenbank-projekt.de/projekte/improved-enhanced-message-box-ms-access
However, a request for paid help was unanswered.
After spending a morning with ChatGPT trying various fixes that did not work, I wondered if any other developers had any ideas or perhaps had experienced a similar issue.
Thanks,
Finlay McMillan
'-----------------------------------------------------------------------------
' Plain Text Replacement for the standard MsgBox
'-----------------------------------------------------------------------------
Public Function Box(ByVal Prompt As String, _
Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, _
Optional ByVal Title As String, _
Optional ByVal HelpFile As String, _
Optional ByVal HelpContextId As Long, _
Optional ByVal ButtonDelay As Long = -1, _
Optional ByVal AllowBeep As Variant, _
Optional ByVal AllowCopyToClipboard As Variant, _
Optional ByVal AllowSaveToFile As Variant, _
Optional ByVal LabelButton1 As Variant = Null, _
Optional ByVal LabelButton2 As Variant = Null, _
Optional ByVal LabelButton3 As Variant = Null, _
Optional ByVal NoStrEsc As Variant, _
Optional ByVal DismissID As Variant = Null, _
Optional ByVal AutoCloseSec As Long = 0, _
Optional ByVal DefaultButton As Long = 0, _
Optional ByVal BGColorButton1 As Long = -1, _
Optional ByVal BGColorButton2 As Long = -1, _
Optional ByVal BGColorButton3 As Long = -1, _
Optional ByVal BoxIsModal As Boolean = True, _
Optional ByVal BoxIsOnTop As Boolean = True, _
Optional ByVal DelayShow_Countdown As Boolean = False) _
As VbMsgBoxResultEx
' If the dialog was previously dismissed, don't display anything at all
If (Buttons And 7) = 0 And GetDismissIDValue(DismissID) Then
Box = VbMsgBoxResultEx.vbOK
Exit Function
End If
' Create the MessageBox
Dim F As New Form_frmEnhancedMessageBoxFormDialog
F.ParenthWnd = GetParentWindowHandle()
F.Title = Title
F.Buttons = Buttons
F.HelpFile = HelpFile
F.HelpContextId = HelpContextId
F.ButtonDelay = IIf(ButtonDelay <= 0, DefaultButtonDelay, ButtonDelay)
F.AllowBeep = IIf(IsMissing(AllowBeep), DefaultBeepAllowed, AllowBeep)
F.AllowCopyToClipboard = IIf(IsMissing(AllowCopyToClipboard), DefaultCopyToClipboardAllowed, AllowCopyToClipboard)
F.AllowSaveToFile = IIf(IsMissing(AllowSaveToFile), DefaultSaveToFileAllowed, AllowSaveToFile)
F.SavedTextFileFolder = DefaultSavedTextFileFolder
F.IsRichText = False
F.LabelButton1 = LabelButton1
F.LabelButton2 = LabelButton2
F.LabelButton3 = LabelButton3
F.DismissID = DismissID
F.AutoCloseSec = IIf(IsMissing(AutoCloseSec), DefaultAutoCloseSecDelay, AutoCloseSec)
F.DefaultButton = IIf(IsMissing(DefaultButton), DefaultDefaultButton, DefaultButton)
F.BGColorButton1 = IIf(BGColorButton1 < 0, DefaultBGColorButton1, BGColorButton1)
F.BGColorButton2 = IIf(BGColorButton2 < 0, DefaultBGColorButton2, BGColorButton2)
F.BGColorButton3 = IIf(BGColorButton3 < 0, DefaultBGColorButton3, BGColorButton3)
F.BoxIsModal = IIf(IsMissing(BoxIsModal), DefaultBoxIsModal, BoxIsModal)
F.BoxIsOnTop = IIf(IsMissing(BoxIsOnTop), DefaultBoxIsOnTop, BoxIsOnTop)
F.DelayShow_Countdown = IIf(IsMissing(DelayShow_Countdown), DEFAULT_DELAYSHOW_COUNTDOWN, DelayShow_Countdown)
If IIf(IsMissing(NoStrEsc), DefaultNoStrEsc, NoStrEsc) Then
F.Prompt = Prompt
Else
F.Prompt = UnEscStr(Prompt, toHtml:=False)
End If
' Make it visible and wait for the user until we get the result
Box = F.ShowModal()
' Keep the last result just in case the user needs it again later
m_Result = Box
' Set focus back to the parent form
On Error Resume Next
WinAPISetFocus F.ParenthWnd
On Error GoTo 0
' cleanup
Set F = Nothing
3 Replies
- Finlay McMillanCopper Contributor
Thanks for your responses.
I added the following code as a workaround:
' cleanup
Set F = Nothing'
' Fix to ensure form closes after user response
'
Dim I As Integer
For I = Forms.Count - 1 To 0 Step -1
If Forms(I).Name = "frmEnhancedMessageBoxFormDialog" Then
DoCmd.Close acForm, Forms(I).Name, acSaveNo
End If
Next I - arnel_gpIron Contributor
I think you need to directly inform the author about this, so he can fix the issue.
- Tom_van_StiphoutIron Contributor
There is more relevant code than you're showing here.
Can you please create a working app that has all the code to demonstrate the problem, and that compiles?
For example, several of the modal form's procedures are relevant as well. ShowModal is probably implemented there as well (it is not part of the Access.Form object).