InputBox function

aziz rasul

Active member
Local time
Today, 15:01
Joined
Jun 26, 2000
Messages
1,935
I have the following code, which prompts the user to enter a numerical number: -

Code:
            strPrints = InputBox("Enter the number of practitioners who will need a copy of the letter?", "Sandwell Primary Care Trust", intPractitioners)
            If strPrints = "" Then
                intPrints = 1
            Else
                intPrints = CInt(strPrints)
            End If

If the user enters say 'two' instead of 2, how can I get the InputBox to keep on reappearing until the user either presses Cancel on the InputBox or enters a numerical value?
 
Your might try this:

Code:
    Dim intPractitioners
    Dim strPrints As String
    Dim intPrints As Integer
    Dim strMsg As String
 
    strMsg = "Enter the number of practitioners " & _
    "who will need a copy of the Letter."
 
    intPractitioners = 1 'Default 1 copy
 
TryAgain:
 
    strPrints = InputBox(strMsg, "Sandwell Primary Care Trust", intPractitioners)
 
        If strPrints = "" Then
            ' Cancel button pressed so don't do anything
            ' Just exit the sub.
            Exit Sub
        ElseIf Not IsNumeric(strPrints) Then
            strMsg = strMsg & Chr(13) & "Please enter a number. Exam: 1, 2, 3, etc."
            GoTo TryAgain
        Else
            intPrints = CInt(strPrints)
        End If
 
        'Code to do print the job(s) goes below.

Regards

Richard
 
Last edited:
Thanks Richard. That worked.
 

Users who are viewing this thread

Back
Top Bottom