• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

Messagebox question. (with Yes to all, Not to all button)

0
yongyih
Asked:
yongyih
  • 3
1 Solution
 
zzzzzoocCommented:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/messagebox.asp

As per the MSDN documentation for MessageBox, "yes to all" and "no to all" is not supported. You'll have to create your own form with Command Buttons and use it to act as a MessageBox. You can do this by using the vbModal option in the Show() method of a Form.

Example..

Private Sub Form_Load()
    Call Form1.Show
    Call Form2.Show(vbModal)
End Sub
0
 
dbrckoviCommented:
Create new form ( Form2 )
Place label and two command buttons ( set Their captions to "Yes to All" and "No to all" )

Paste this code to form1:
----------------------------------
Function myMsgBox(ByVal Message As String, ByVal Title As String)
    Load Form2
    Form2.Top = Screen.Height / 2 - Form2.Height / 2
    Form2.Left = Screen.Width / 2 - Form2.Width / 2
    Form2.Label1.Caption = Message
    Form2.Caption = Title
    Form2.Show (vbModal)
    myMsgBox = Form2.Response
    Unload Form2
End Function

Private Sub Command1_Click()
    Print myMsgBox("Select an option. First button will return True" & Chr(13) & "and the second one False", "Question")
End Sub
----------------------------------
and this to form2
----------------------------------
Public Response As Boolean

Private Sub Command1_Click()
    Response = True
    Me.Hide
End Sub

Private Sub Command2_Click()
    Response = False
    Me.Hide
End Sub

Private Sub Form_Activate()
    Response = False
End Sub
------------------------------------------
0
 
dbrckoviCommented:
You can make this function more flexible by replacing it with this:
It will allow you to specify button captions.

Function myMsgBox(ByVal Message As String, ByVal Title As String, ByVal Caption1 As String, Caption2 As String)
    Load Form2
    Form2.Top = Screen.Height / 2 - Form2.Height / 2
    Form2.Left = Screen.Width / 2 - Form2.Width / 2
    Form2.Label1.Caption = Message
    Form2.Caption = Title
    Form2.Command1.Caption = Caption1
    Form2.Command2.Caption = Caption2
    Form2.Show (vbModal)
    myMsgBox = Form2.Response
    Unload Form2
End Function

Private Sub Command1_Click()
    Print myMsgBox("Select an option. First button will return True" & Chr(13) & "and the second one False", "Question", "Yes To All", "No To All")
End Sub
0
 
dbrckoviCommented:
thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now