PDA

View Full Version : [SOLVED:] Cancel Button for Input Box



bartoni
07-12-2004, 05:14 AM
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"

Richie(UK)
07-12-2004, 05:29 AM
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

bartoni
07-12-2004, 07:34 AM
Thanks for that!!!