[RESOLVED] MsgBoxStyle as Variable Type mismatch
Hi ,
I wanna make MsgBoxStyle as Variable
i have 4 option
each one save
vbCritical
vbQuestion
vbExclamation
vbInformation
i do code like this
Code:
Dim opvalue As String
If Op1.value = True Then opvalue = "vbInformation"
If Op2.value = True Then opvalue = "vbQuestion"
If Op3.value = True Then opvalue = "vbCritical"
If Op4.value = True Then opvalue = "vbExclamation"
MsgBox "testing", vbOKOnly + opvalue, "test"
it cause exception type mismatch
what i'am doing wrong ?
Thanks
Re: MsgBoxStyle as Variable Type mismatch
Value must be of an Integer type - not string.
You can do something like this:
Code:
Option Explicit
Private Enum myMsgStyle
msgInformation = VBA.VbMsgBoxStyle.vbInformation
msgQuestion = VBA.VbMsgBoxStyle.vbQuestion
msgCritical = VBA.VbMsgBoxStyle.vbCritical
msgExclamation = VBA.VbMsgBoxStyle.vbExclamation
End Enum
Private Sub Command1_Click()
Dim opvalue As Integer
If Op1.Value = True Then opvalue = myMsgStyle.msgInformation
If Op2.Value = True Then opvalue = myMsgStyle.msgQuestion
If Op3.Value = True Then opvalue = myMsgStyle.msgCritical
If Op4.Value = True Then opvalue = myMsgStyle.msgExclamation
End Sub
or this
Code:
Private Sub Command1_Click()
Dim opvalue As Integer
If Op1.Value = True Then opvalue = VBA.VbMsgBoxStyle.vbInformation
If Op2.Value = True Then opvalue = VBA.VbMsgBoxStyle.vbQuestion
If Op3.Value = True Then opvalue = VBA.VbMsgBoxStyle.vbCritical
If Op4.Value = True Then opvalue = VBA.VbMsgBoxStyle.vbExclamation
End Sub
Re: MsgBoxStyle as Variable Type mismatch
Yes must be Integer not String
Thanks m8 ;)