在 vbYes vbNo msgbox 之后使用输入框,然后继续

Using an inputbox after a vbYes vbNo msgbox, and continue on

我的数据库中有一个 vbYes/vbNo MsgBox,但我想继续使用进一步的输入框提示。但是,它给我以下错误:

Block if without 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")

因为您在 If Answer1=vbYes Then 之后将 InputBox 放在了新的一行上,Access 需要 End If 来关闭该代码块。

但是,由于您通过将 MsgBox 的结果与 vbYes 进行比较来初始化 Answer1 的方式,Answer1 将是 True(如果用户点击 "Yes") 或 False.

您的代码可以修改为:

If vbYes=MsgBox("Will you be using any compensatory time?", vbYesNo + vbQuestion) 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

请注意,我已将 vbYes 放在相等检查的左侧 - 这使得在有大量文本时更容易阅读,而无需一直滚动到右侧。

此致,

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

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) - MsgBoxvbYes.

返回值的比较结果

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

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