Capturing the value of the button clicked on a msgbox
Hi guys
I need to find out which button has been clicked on a msgbox and then show the user via a text box on my form.
I have written a program demonstrating the various icon/button combinations for a msgbox. Everything works great. All i need to do now is find out which button on the msgbox the user pressed and display this info in a text box on the form.
Can anyone help please??
Ben
Yes that works but. . . . . .
I need to repeat the same bit of code over and over for each of the buttons on each msgbox that appears. If you look at my code below you will see what I mean.
Is there any way of typing the code (in the replies above) just once and using it for all of the msgboxes?? Maybe by putting the code above into a module??
Thanks in advance guys and gals!!!
Re: Yes that works but. . . . . .
Quote:
Originally posted by brjames
...If you look at my code below you will see what I mean....
Where is the code?
sorry here it is. . . . . . .
VB Code:
Private Sub cmdShow_Click()
Dim answer As VbMsgBoxResult
Dim MsgBoxStyle As VbMsgBoxStyle
If optButton(0).Value Then
MsgBoxStyle = vbOKOnly
ElseIf optButton(1).Value Then
MsgBoxStyle = vbOKCancel
ElseIf optButton(2).Value Then
MsgBoxStyle = vbYesNo
ElseIf optButton(3).Value Then
MsgBoxStyle = vbYesNoCancel
ElseIf optButton(4).Value Then
MsgBoxStyle = vbRetryCancel
ElseIf optButton(5).Value Then
MsgBoxStyle = vbAbortRetryIgnore
End If
If optIcon(0).Value = True Then
MsgBoxStyle = MsgBoxStyle
ElseIf optIcon(1).Value = True Then
MsgBoxStyle = MsgBoxStyle + vbCritical
ElseIf optIcon(2).Value = True Then
MsgBoxStyle = MsgBoxStyle + vbExclamation
ElseIf optIcon(3).Value = True Then
MsgBoxStyle = MsgBoxStyle + vbCritical
ElseIf optIcon(4).Value = True Then
MsgBoxStyle = MsgBoxStyle + vbInformation
ElseIf optIcon(5).Value = True Then
MsgBoxStyle = MsgBoxStyle + vbInformation
ElseIf optIcon(6).Value = True Then
MsgBoxStyle = MsgBoxStyle + vbQuestion
ElseIf optIcon(7).Value = True Then
MsgBoxStyle = MsgBoxStyle + vbCritical
ElseIf optIcon(8).Value = True Then
MsgBoxStyle = MsgBoxStyle + vbExclamation
End If
MsgBox txtMessage.Text, MsgBoxStyle, txtTitle.Text
txtResult.Text = answer
End Sub