Использование поля ввода после сообщения vbYes vbNo и продолжить - PullRequest
0 голосов
/ 22 апреля 2020

У меня есть часть vbYes / vbNo MsgBox в моей базе данных, но любой ответ я хотел бы продолжить с дальнейшими подсказками ввода. Тем не менее, он дает мне следующую ошибку:

Блокировать, если без конца, если

Есть идеи, как сохранить этот проект в движении?

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")

Ответы [ 2 ]

1 голос
/ 23 апреля 2020

Ошибка возникает из-за того, что для каждого из ваших операторов 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
1 голос
/ 23 апреля 2020

Поскольку вы поставили 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 слева от проверки на равенство - это облегчает чтение при большом количестве текста без необходимости прокручивать весь путь до право.

С уважением,

...