Announcement

Collapse
No announcement yet.

Inputbox Error when user clicks on cancel Button

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inputbox Error when user clicks on cancel Button



    I would just like to exit the macro in case the user clicks on the cancel button instead of inputing a value in the inputbox.



    Is there any way I can avoid the macro from running and giving me an error
    message.

    Thank You

    Vik

  • #2
    Re: Inputbox Error when user clicks on cancel Button

    If the user clicks the Cancel button a null string is assigned, therefore, check for a null string.

    Code:
    Response = InputBox("Please enter the data.")
    If Response = "" Then Exit Sub
    Bill
    Bill
    Tip: To avoid chasing code always use Option Explicit.

    Comment


    • #3
      Re: Inputbox Error when user clicks on cancel Button

      Howdy. You can add this prior to the line with the Inputbox.

      Code:
          On Error Resume Next
      Also, are you using the Inputbox or the Application.Inputbox?

      Try this:

      Code:
          On Error Resume Next
          Set StartCell = Application.InputBox(prompt:="Select Start Cell", Type:=8)

      Software: OpenOffice 3.0/NeoOffice 3.0 on Mac OS X 10.5.6
      Humanware: Older than dirt

      Old, slow, and confused - but at least I'm inconsistent!

      Rich
      (retired Excel 2003 user, 3.28.2008)

      Comment


      • #4
        Re: Inputbox Error when user clicks on cancel Button

        Thanks Shades,

        I guess I did not explain the problem. Its no big deal though.

        I am pulling information from an External Access Database through a macro and then manipulating it to create reports. My macro works perfectly and multiple users with different file paths to this Access Database can run it
        - I was just wondering whether there was a way to exit the macro incase somebody clicks on the cancel button when the inputbox asks to check whether the existing file path is correct.

        I tried On error Goto ... (end of the macro)

        I can avoid the error message but the macro still runs ?

        Thanks for your help

        Vik

        Comment


        • #5


          Re: Inputbox Error when user clicks on cancel Button

          Instead of On Error Resume Next, put this line above the Inputbox:

          Code:
          On Error GoTo Canceled
          Then at the very bottom of the sub (right before the line End Sub) put this:

          Code:
          Canceled:
          End Sub

          Software: OpenOffice 3.0/NeoOffice 3.0 on Mac OS X 10.5.6
          Humanware: Older than dirt

          Old, slow, and confused - but at least I'm inconsistent!

          Rich
          (retired Excel 2003 user, 3.28.2008)

          Comment

          Working...
          X