Search code examples
ms-accessmsgbox

"No" selection takes me to the wrong next msgbox input


If vbYes = MsgBox("Do you have Federal Employee Health Benefits (FEHBB), such as Blue Cross Blue Shield?", vbYesNo + vbQuestion) Then
End If
If vbYes = MsgBox("Would you like to terminate/suspend your Federal Employee Health Benefits (FEHB) while on orders?", vbYesNo + vbQuestion) Then
    FEHBCancel = InputBox("Please initial here to cancel/suspend your FEHB.")
Else
NoFEHB = InputBox("Please initial here indicating that you do not have Federal Employee Health Benefits.")
End If

Above seemed to run through, but the problem I'm running into now is when I ask the first msgbox "Do you have FEHB..." if I select "No", I want it to move on to a new msgbox "please initial here indicating that you do not have...". If the answer is "YES", then I'd like to it go to msgbox "do you want to terminate", another Yes/No msgbox. And from there, potentially another box if they select "no" they don't want to terminate.


Solution

  • Below is some VBA code that shows how this should be done. When doing this sort of thing, it often helps to draw out on a piece of paper the logic process, and when coding the If statements, always indent each nested level to maintain readability.

    Sub sMsg()
        Dim strTerminate As String, strPayFor As String, strNoFEHBB As String
        If vbYes = MsgBox("Do you have FEHBB?", vbYesNo) Then
            If vbYes = MsgBox("Do you want to terminate", vbYesNo) Then
                strTerminate=InputBox("Please initial to terminate")        
            Else    '   No they don't want to terminate
                strPayFor=InputBox("Please initial to pay")
            End If
        Else    ' do not have FEHBB
            strNoFEHBB = InputBox("Please initial here")
        End If
    End Sub
    

    Regards,