Consulting

Results 1 to 3 of 3

Thread: Cancel Button for Input Box

  1. #1
    VBAX Regular
    Joined
    Jul 2004
    Posts
    16
    Location

    Cancel Button for Input Box

    Hi,

    This is my code which asks for user input and opens specfic workbooks accordingly. The problem is if is start the first inputbox (country) and click cancel on the inputbox, it doesnt cancel but brings up the next input box. How do you make the cancel button stop the macro?



    Sub old_access()
    country = InputBox("Data from which Analogue country:")
    quarter = InputBox("Data from which Analogue production (i.e 403) :") 
    Workbooks.Open FileName:="c:\macros\" & country & "_promo_q" & quarter & ".xls"
    Workbooks.Open FileName:="c:\macros\" & country & "_profile_q" & quarter & ".xls"
    Workbooks.Open FileName:="C:\macros\test.xls"
    Last edited by Aussiebear; 04-29-2023 at 09:28 PM. Reason: Adjusted the code tags

  2. #2
    VBAX Contributor Richie(UK)'s Avatar
    Joined
    May 2004
    Location
    UK
    Posts
    188
    Location
    Hi b,

    You need to evaluate the response that you receive and then decide how the code should proceed. In the following example the sub exits if no response is given.

    Sub old_access()
        Dim country As String
    country = InputBox("Data from which Analogue country:")
        If country = "" Then Exit Sub
        MsgBox country
    End Sub
    Last edited by Aussiebear; 04-29-2023 at 09:29 PM. Reason: Adjusted the code tags

  3. #3
    VBAX Regular
    Joined
    Jul 2004
    Posts
    16
    Location
    Thanks for that!!!

Posting Permissions

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