vba - 在 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")
解决方案
出现错误是因为您的每个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
它将包含一个布尔值 (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
推荐阅读
- python - 如何尽可能多地用字符串内容填充 n 个表?
- android - Flutter,在 Android 上同时使用调试键和释放键进行签名
- oracle - Oracle在循环期间修改游标值
- javascript - 异步功能完成后执行代码
- angular - angular 4 typescript validation error Object literal may only specify known properties
- javascript - React - 选择具有与 HTML5 选择元素类似的 API 的组件
- javascript - 在 IE 中添加/删除选择列表选项
- acumatica - 从 PO 订单行到 ReceiptLine 的承诺日期
- python - 识别连续重复的子序列数组
- angularjs - 作为 DOM 兄弟的指令元素