如何在if语句中对消息框vbyesno进行编码以自动填充userform

时间:2017-09-24 12:15:43

标签: excel-vba vba excel

我一直在尝试各种替代方法来编写我在VBA excel中的If语句中的消息框但是没有运气。

我有一个带有多个文本框的用户表单,用于输入数据。我正在尝试将一组规则构建到一个命令按钮中,该按钮旨在消除数据捕获活动中的经验/知识。

根据第一个组合框中的输入(txt_Secondary_Reason)结合消息框/后续组合框的响应,我希望自动填充以下字段。

请参阅以下代码:

`If txt_Secondary_Reason.Value = "DON'T KNOW WHERE FITS" Then
ComboBox_Problem_Mode.Value = "PART NOT FITTED"
ComboBox_Problem_Mode_1.Value = "DON'T KNOW WHERE FITS"
ComboBox_Root_Mode.Value = "DON'T KNOW WHERE FITS"
ComboBox_Root_Cause.Value = "DON'T KNOW WHERE FITS"

ElseIf txt_Secondary_Reason.Value = "BOM INCORRECT" And Response = 
MsgBox("Has QIR for this Non Conformance been raised?", vbYesNo + 
vbQuestion, "QIR?") Then
Select Case Response
Case Is = vbYes
    ComboBox_Problem_Mode_1.Value = "QIR RAISED"
    ComboBox_Problem_Mode.Value = "PART NOT FITTED"
    ComboBox_Root_Mode.Value = "NON CONFORMING"
    ComboBox_Root_Cause.Value = "BOM INCORRECT"

Case Is = vbNo
    ComboBox_Problem_Mode_1.Value = "QIR NOT RAISED"
    ComboBox_Problem_Mode.Value = "PART NOT FITTED"
    ComboBox_Root_Mode.Value = "NON CONFORMING"
    ComboBox_Root_Cause.Value = "BOM INCORRECT"
End Select
End If
----------------------------------------------------------------------------
----`

“txt_Secondary_Reason”是一个组合框,它最初是一个文本框。

根据此处的输入以及文本框询问用户是否已满足某个条件,两个结果中的一个必须生效,然后移至下一个其他...

非常感谢您的帮助

此致 Zunaid

1 个答案:

答案 0 :(得分:0)

代码就像这样

If txt_Secondary_Reason.Value = "DON'T KNOW WHERE FITS" Then
    ComboBox_Problem_Mode.Value = "PART NOT FITTED"
    ComboBox_Problem_Mode_1.Value = "DON'T KNOW WHERE FITS"
    ComboBox_Root_Mode.Value = "DON'T KNOW WHERE FITS"
    ComboBox_Root_Cause.Value = "DON'T KNOW WHERE FITS"

ElseIf txt_Secondary_Reason.Value = "BOM INCORRECT" Then
    Response = MsgBox("Has QIR for this Non Conformance been raised?", vbYesNo + vbQuestion, "QIR?")
    Select Case Response
    Case Is = vbYes
        ComboBox_Problem_Mode_1.Value = "QIR RAISED"
        ComboBox_Problem_Mode.Value = "PART NOT FITTED"
        ComboBox_Root_Mode.Value = "NON CONFORMING"
        ComboBox_Root_Cause.Value = "BOM INCORRECT"

    Case Is = vbNo
        ComboBox_Problem_Mode_1.Value = "QIR NOT RAISED"
        ComboBox_Problem_Mode.Value = "PART NOT FITTED"
        ComboBox_Root_Mode.Value = "NON CONFORMING"
        ComboBox_Root_Cause.Value = "BOM INCORRECT"
    End Select
End If