+ Reply to Thread
Results 1 to 5 of 5

Error Prevention Application.InputBox

  1. #1
    Registered User
    Join Date
    05-28-2008
    Posts
    49

    Error Prevention Application.InputBox

    I am trying to add error prevention to my macro.

    Please Login or Register  to view this content.
    In all dialog box prompts for user input, if a character is input when the a numberic is requested or the user selects the Cancel button, the macro exits.

    This works just as intended. However, for the code in red, if the user inputs a numeric instead of a character, the type:=2 critieria is ignored, the macro accepts the input (when it should not), and moves on to the next dialog box. Additionally, if the user selects the Cancel button, the macro moves on to the next dialog box instead of exiting. What additional code is needed to prevent the macro from proceeding to the next dialog box?

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Error Prevention Application.InputBox

    Given the variable is defined as a String you could check (post InputBox) both:

    a) Val(variable)

    b) variable = "False"

    By the sounds of it either of the above should ever return True the response is not valid.

  3. #3
    Registered User
    Join Date
    05-28-2008
    Posts
    49

    Re: Error Prevention Application.InputBox

    Ok, I think I see what you are saying - since the variable is defined as a string, a numeric value entered into a string defined variable will be treated as a string. Thus, the macro accepts the input and proceeds.

    If I followed correctly, then I propose the following:

    Please Login or Register  to view this content.
    The problem I am having with this approach is that if the input happens to be a value, the macro exits the sub. I thought by adding:

    Please Login or Register  to view this content.
    that the macro would return to the section of the code causing the problem until the input is corrected.

    However, this is not happening. The macro just proceeds.

    What do I need to do?

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Error Prevention Application.InputBox

    If you insist a repeat of the loop you obviously restrict flexibility but in basic terms

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-28-2008
    Posts
    49

    Re: Error Prevention Application.InputBox

    Thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1