首页 > 解决方案 > 在 vbYes vbNo msgbox 之后使用输入框,然后继续

问题描述

我有一个vbYes/vbNo MsgBox部分进入我的数据库,但无论是哪个答案,我都想继续输入进一步的输入框提示。但是,它给了我以下错误:

如果没有 End if 则阻塞

任何想法如何保持这个项目的进展?

Answer1 = MsgBox("Will you be using any compensatory time?", vbYesNo + vbQuestion) = vbYes
If Answer1 = vbYes Then
CompTimeInfo = InputBox("You will need to calculate which days, and how many total hours of comp time you will use. Your comp time should be used up front, as in, if your orders begin on the 1st, you should use them on the next working day straight through. The next prompts will ask for this information. Please initial in the below box.", "AUS Date Initials")
If Answer1 = vbNo Then
AUSDateWithoutComp = InputBox("Please initial here, indicating that you will not be using comp time. This signifies that your AUS start date aligns with your orders start date.", "AUS Start date - No Comp Time")

标签: vbams-accessinputboxmsgbox

解决方案


出现错误是因为您的每个If语句都需要相应的End If终止符。IfVB 中语句的一般语法是:

If <test-expression> Then
    <then-expression1>
    ...
    <then-expressionN>
End If

或者有一个Else论点:

If <test-expression> Then
    <then-expression1>
    ...
    <then-expressionN>
Else
    <else-expression1>
    ...
    <else-expressionN>
End If

因此,为了在语法上正确,您的代码应变为:

Answer1 = MsgBox("Will you be using any compensatory time?", vbYesNo + vbQuestion) = vbYes
If Answer1 = vbYes Then
    CompTimeInfo = InputBox("You will need to calculate which days, and how many total hours of comp time you will use. Your comp time should be used up front, as in, if your orders begin on the 1st, you should use them on the next working day straight through. The next prompts will ask for this information. Please initial in the below box.", "AUS Date Initials")
End If
If Answer1 = vbNo Then
    AUSDateWithoutComp = InputBox("Please initial here, indicating that you will not be using comp time. This signifies that your AUS start date aligns with your orders start date.", "AUS Start date - No Comp Time")
End if

但是,请注意,您的then表达式将永远不会被评估,因为Answer1它将包含一个布尔值 (true/false) - 比较与返回的值的MsgBox结果vbYes

因此,我建议将您的代码编写为:

If MsgBox("Will you be using any compensatory time?", vbYesNo + vbQuestion) = vbYes Then
    CompTimeInfo = InputBox("You will need to calculate which days, and how many total hours of comp time you will use. Your comp time should be used up front, as in, if your orders begin on the 1st, you should use them on the next working day straight through. The next prompts will ask for this information. Please initial in the below box.", "AUS Date Initials")
Else
    AUSDateWithoutComp = InputBox("Please initial here, indicating that you will not be using comp time. This signifies that your AUS start date aligns with your orders start date.", "AUS Start date - No Comp Time")
End If

推荐阅读