Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input box run around 1

Status
Not open for further replies.

willydude

Programmer
Oct 24, 2006
123
US
If the user selects OK or cancel, then quit. This works.

If the user enters something, then continue
the process. This does not work. If I enter info, it wants to quit. It should not.

I have tried numerous ways with no complete success.

Code:
Static Sub MonthAndYear() 'remember to >>Public ReportMonth As String
Application.StatusBar = "Enter Month and Year"
Application.DisplayAlerts = False
ReportMonth = ""
ReportMonth = Application.InputBox("Enter the FULL name of the month to " _
& "be processed followed by the FOUR DIGIT year. " _
& "If you want to close the workbook and exit, select OK or CANCEL ", _
 "Month and Year", Default:=ReportMonth, Type:=2)
On Error GoTo continue
'On Error GoTo cancelled:
If Len(LTrim(ReportMonth)) = 0 Or ReportMonth = "" Then
        MsgBox "You have chosen to close Commissions Based on Sales"
        Workbooks("CommissionsBySalesQBTestFile.xls").Close
'Else: GoTo cancelled

End If
'cancelled:
MsgBox "You have chosen to close Commissions Based on Sales"
        Workbooks("CommissionsBySalesQBTestFile.xls").Close
continue:
Application.DisplayAlerts = True
Application.StatusBar = False
End Sub
 
Skip,

Yes. Numerous times. I lost count a long time ago.

When stepping thru, when I enter something, the value entered appears when I place my cursor over the variable ReportMonth. This makes sense.

As I continue the code then skips over

Code:
Workbooks("CommissionsBySalesQBTestFile.xls").Close
If Len(LTrim(ReportMonth)) = 0 Or ReportMonth = "" Then
        MsgBox "You have chosen to close Commissions Based on Sales"
        Workbooks("CommissionsBySalesQBTestFile.xls").Close

which it should b/c there is something in the variable ReportMonth. But then it proceeds to

Code:
MsgBox "You have chosen to close Commissions Based on Sales"
        Workbooks("CommissionsBySalesQBTestFile.xls").Close
which it should not. It needs to skip this and move on with processing.

If I select Cancel, I get the same results as when I enter something.

If I select OK, then it quits as it should.
 
It works OK:

You go to this codonly if there is nothing in the input box:

If Len(LTrim(ReportMonth)) = 0 Or _
ReportMonth = "" Then
MsgBox "You have chosen to close
Commissions Based on Sales"
Workbooks("CommissionsBySalesQBTestFile.xls").Close
'Else: GoTo cancelled
End If

You skip this if there is anything in it.

But the rest of the code will run no matter what you put in there, b/c after the line:
'cancelled:
there is no condition to run this code or not. So it runs every time when you have anything in your input box.



Have fun.

---- Andy
 
'Else: GoTo cancelled

You haven't given the script anything to do if the condition is not met. Just because "cancelled:" and "continue:" are labeled doesn't mean they won't be executed if encountered.

_________________
Bob Rashkin
 
What about this ?
Code:
Static Sub MonthAndYear() 'remember to >>Public ReportMonth As String
Dim myVar
Application.StatusBar = "Enter Month and Year"
Application.DisplayAlerts = False
ReportMonth = ""
myVar = Application.InputBox("Enter the FULL name of the month to " _
& "be processed followed by the FOUR DIGIT year. " _
& "If you want to close the workbook and exit, select CANCEL ", _
 "Month and Year", Default:=ReportMonth, Type:=2)
If myVar = False Or Trim(myVar & "") = "" Then
  ' Cancel or nothing entered
  MsgBox "You have chosen to close Commissions Based on Sales"
  Workbooks("CommissionsBySalesQBTestFile.xls").Close
  Exit Sub
End If
'value entered and OK
Application.DisplayAlerts = True
Application.StatusBar = False
ReportMonth = myVar
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Everybody,

What takes me a day to figure out, you've got it in five minutes.

Thanks.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top