在vbYes vbNo msgbox之后使用输入框,并继续前进。

问题描述 投票:0回答:2

我有一个 vbYesvbNo 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")
vba ms-access inputbox msgbox
2个回答
1
投票

因为你把InputBox放在了一个新的行上,然后是 If Answer1=vbYes Then,Access正在等待一个 End If 来关闭该代码块。

然而,由于你初始化了 Answer1 通过比较 MsgBox 到vbYes。Answer1 将是 True (如果用户点击了 "是")或 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 在平等检查的左侧--当有大量文字时,这样可以更容易地阅读,而不必一直向右滚动。

请注意。


1
投票

错误的产生是因为你的每一个 If 语句将需要一个相应的 End If 终止符。终止符的一般语法是 If 在VB中的语句是要么。

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 将包含一个布尔值(truefalse)--比较由 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
© www.soinside.com 2019 - 2024. All rights reserved.