Handling the 'Cancel' button..??

R

RJH

I have the following code:

Do
Msg = "Is the BILLING DATE below correct?" & Chr(10) & Chr(10) _
& "If not, Enter correct date ..."
Default = Worksheets("Sheet2").Range("N2")
BillDate = InputBox(Msg, Title, Default) ' get billing date
Worksheets("Sheet2").Range("N2") = BillDate 'Put BillDate into
Sheet2 N2

If BillDate <> "" Then Exit Do
MsgBox "Please enter Billing Date", 48, Title
Loop

It works like a champ but...
How would I handle someone hitting the 'Cancel button?
At this point if 'Cancel' is pressed I get the "Please enter billing date"
msg and it loops around again.

Thanks for the help.

RJH
 
N

Norman Jones

Hi RJH,

Try:

Do
Msg = "Is the BILLING DATE below correct?" _
& Chr(10) & Chr(10) _
& "If not, Enter correct date ..."

myDefault = Worksheets("Sheet2").Range("N2")
BillDate = InputBox(Msg, Title, myDefault)
Worksheets("Sheet2").Range("N2") = BillDate

If StrPtr(BillDate) = 0 Then
MsgBox "You cancelled"
Exit Do
End If

If BillDate <> "" Then Exit Do
MsgBox "Please enter Billing Date", 48, Title
Loop


Note that I changed your Default variable to myDefault as the former is a
keyword and it use may cause problems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Active sheet? 3
Inputbox and cancel button 5
Subscript Out of Range Error 16
Filter Problem 2
Workbook_BeforeSave Event 4
copy dates 1
Creating a list box 1
Snag in invoice generator. How to change the "series" 5

Top