How do you make a MsgBox with a “Do Not Ask This Again” or “Don't Ask Me Again” Checkbox in VB6?

StackOverflow https://stackoverflow.com/questions/1040413

  •  22-07-2019
  •  | 
  •  

Question

I ask this partly because I want to know the best practice way of doing this, and partly because the top google result I got was a forum thread from 2002 in which the question wasn't even answered.

I inherited some VB6 code, and there are some MsgBox calls in said code, many of which display messages that end users would probably find very annoying after a short time (e.g. "Printing Complete," "Record Added," etc.)

I would like to add the standard user interface control of a checkbox on the MsgBox saying "Don't ask me this again", so that when checked and OK is clicked, a setting is saved that lets the program know, you know...to never ask that again. Pretty standard control, the idea is fairly self-explanatory.

What I would like to know is what is the best practice way of doing this in VB6. There is the obvious way of just making a new form for these type of msgboxen and replacing the old MsgBox call with a .Show on that form, but do the VB6 gurus on Stack Overflow have a better way?

Thanks in advance

Was it helpful?

Solution

As far as I know, there is no other way. You need to make your own message box form with the check box. Of course, you'll also need to modify the code to store and retrieve this setting (and acting appropriately based on the setting).

I have done this in my own application many times. One thing to think about.... suppose the user checks the box "don't show me this again". In my opinion, there should be a way to reset the setting. Since the message box form won't show again, I added this to the configuration form (for my app).

One thing you may want to consider is sub-classing the MSGBOX function. You could create a function within your app that has a similar parameter list, but with a couple extra. If the extra parameters are missing, simply call vba.MsgBox (to get the standard behaviour). If you pass in extra parameters, you could call your new form instead.

OTHER TIPS

Well... You are not absolutely correct guys ;)

Starting from Win2000, there's SHMessageBoxCheck function that does the trick. VB6 declaration:

Private Declare Function SHMessageBoxCheck Lib "shlwapi" Alias "#185" (ByVal hWnd As Long, ByVal lpszText As String, ByVal lpszTitle As String, ByVal dwType As VbMsgBoxStyle, ByVal iDefault As Long, ByVal lpszId As String) As Long

For everything else follow the link :)

If you provide such a functionality, it might require "turning-on" of showing messagebox.
i.e. user should have an option to see the msgbox again using some setting.

Instead of that, you could use statusbar to display notifications OR have a label with the notification messages and turn it off after a few seconds.

This was my down and dirty solution:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
myfile = Workbooks.Application.ActiveWorkbook.Path & "\noprompt.txt"
If Dir(myfile) <> "" Then Exit Sub
exportData = MsgBox("Export data?" & vbCrLf & "Select Cancel (or × top right) to prevent this prompt from displaying again.", vbYesNoCancel, "Close Workbook")
If exportData = vbYes Then
    Call ExportValues 'a separate function...
ElseIf exportData = vbCancel Then
    'create file noprompt.txt
    Open myfile For Output As #1
    Write #1, "Delete this file to restore prompt to Export Data when workbook is closed."
    Close #1
    Exit Sub
ElseIf exportData = vbNo Then
    Exit Sub

End If


End Sub

Documentation for my app explains that deleting the file restores the prompt.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top