1
votes

I am trying to figure out how to make sure data is entered into the InputBox at each stage (otherwise I want the message to pop-up and the entry to end). I have a MsgBox that pops up if nothing is entered but I want to add an option to have the Sub remain at the InputBox it is at so the user can still enter the data.

I've tried using vbRetryCancel and either the Retry will loop and then never actually cancel (and I have to force outlook to close to end the macro) or the Cancel will loop and it will never retry. If I could make it so the InputBox would not advance with "Ok" until data is entered or "cancel" was clicked that would work too but I would still need a MsgBox if nothing is entered to alert the user.

    Sub Request_Tracking()

Dim objMsg As MailItem
Dim tasksource As String
Set objMsg = Application.CreateItem(olMailItem)

'requests input of the user with various options
tasksource = InputBox("Please select task receipt method:" & _
        vbCrLf & vbTab & "1 - Phone call" & _
        vbCrLf & vbTab & "2 - Email" & _
        vbCrLf & vbTab & "3 - Instant Message" & _
        vbCrLf & vbTab & "4 - Desk walk-up" & _
        vbCrLf & vbTab & "5 - Miscellaneous", "Option Chooser")

    'if response is blank then ends the task
    If tasksource = vbNullString Then
        MsgBox "Nothing was entered. Please re-enter your request.", vbOKOnly, "Error!"
        Exit Sub
    End If

    Select Case tasksource
        Case "1"
            tasksource = "Phone call"
        Case "2"
            tasksource = "Email"
        Case "3"
            tasksource = "Instant Message"
        Case "4"
            tasksource = "Desk walk-up"
        Case "5"
            tasksource = "Miscellaneous"
        Case Else
            tasksource = tasksource
    End Select

    'various input boxes for data needed, if response is blank then ends the task without send
    strName = InputBox("Requestor Name:")
        If strName = vbNullString Then
            MsgBox "Nothing was entered. Please reattempt your request.", vbOKOnly, "Error"
            Exit Sub
        End If
    strCoreEvent = InputBox("Task Description:")
        If strCoreEvent = vbNullString Then
            MsgBox "Nothing was entered. Please reattempt your request.", vbOKOnly, "Error"
            Exit Sub
        End If
    strUnitNum = InputBox("Number of units:")
        If strUnitNum = vbNullString Then
            MsgBox "Nothing was entered. Please reattempt your request.", vbOKOnly, "Error"
            Exit Sub
        End If
    strTime = InputBox("Processing Time:")
        If strTime = vbNullString Then
            MsgBox "Nothing was entered. Please reattempt your request.", vbOKOnly, "Error"
            Exit Sub
        End If

    'configures message being sent, sents to WFM box and formats the body font and various line breaks and then sends
    With objMsg
        .To = "[email protected]"
        .Subject = "Request Received"
        .HTMLBody = "<body style=font-size:11pt;font-family:Arial><b>For request tracking; please assign to me.</b>" & "<p>" & tasksource & " request from " & strName & ": " & strCoreEvent & "<br />Number of units: " & strUnitNum & "<br />Processing time: " & strTime & "</p></body>"
        .Recipients.ResolveAll
        .Send
    End With

End Sub
2
Do you want to make it mandatory for the user to enter data in inputbox? - Pankaj Jaju
@PankajJaju yes I do. I am unsure how would be the easiest way to do that - jnjustice

2 Answers

2
votes

Your can try something like this:

While tasksource = " "
    tasksource = InputBox("Please select task receipt method:" & _
    vbCrLf & vbTab & "1 - Phone call" & _
    vbCrLf & vbTab & "2 - Email" & _
    vbCrLf & vbTab & "3 - Instant Message" & _
    vbCrLf & vbTab & "4 - Desk walk-up" & _
    vbCrLf & vbTab & "5 - Miscellaneous", "Option Chooser", " ")
    If tasksource = vbNullString Then
        Exit Sub
    ElseIf (tasksource = " ") Then
        tasksourceCancel = MsgBox("Nothing was entered. Please re-enter your request. Or press Cancel to leave!", vbOKCancel, "Error!")
        If tasksourceCancel = 2 Then
            Exit Sub
        End If
    End If
Wend

It forces the user to have Input, if user clicks OK the return/default value will be " " (space) will loop, if the user clicks cancel the value will be vbNullString and it will exit.

0
votes

Try something like this

Do
    tasksource = InputBox("Please select task receipt method:" & _
            vbCrLf & vbTab & "1 - Phone call" & _
            vbCrLf & vbTab & "2 - Email" & _
            vbCrLf & vbTab & "3 - Instant Message" & _
            vbCrLf & vbTab & "4 - Desk walk-up" & _
            vbCrLf & vbTab & "5 - Miscellaneous", "Option Chooser", 1)
            If Not (tasksource >=1 And tasksource <=5) Then
                optionvar = MsgBox("Incorrect selection. Do you want to re-enter your request?", vbYesNo, "Input required")
                If optionvar = 6 Then 'if yes is pressed
                    tasksource = vbNullString
                Else
                    tasksource = optionvar
                End If
            End If
Loop While tasksource = vbNullString