Search code examples
vbams-accessinputboxmsgbox

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


I have a vbYes/vbNo MsgBox partway into my database, but either answer I would like to continue on with further inputbox prompts. However, it is giving me the following error:

Block if without End if

Any ideas how to keep this project moving?

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

Solution

  • Because you have put the InputBox on a new line after If Answer1=vbYes Then, Access is expecting an End If to close that block of code.

    However, because of the way that you are initializing Answer1 by comparing the result of the MsgBox to vbYes, Answer1 will be either True (if the user clicked "Yes") or False.

    Your code can be modified to look like:

    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
    

    Note that I've put vbYes on the left side of the equality check - this makes it easier to read when there is a lot of text without having to scroll all of the way to the right.

    Regards,