Need to Stop Execution if INPUTBOX is Cancelled


Posted by David Holstein on September 29, 2001 6:16 AM

Hi,

Does anybody know how to stop the execution of code if the CANCEL button is clicked or if the INPUTBOX response is null. The code i am using is as follows:

Dim Message, Title, RepName
Message = "Enter the Sales Rep's Name!"
Title = "Sales Representative"
RepName = InputBox(Message, Title)

I have tried:

If RepName = "False" Then End (as works with MSGBOX) and
If IsNull (RepName) Then End

Any help would be appreciated.

Regards
David

Posted by Russell Hauf on September 29, 2001 7:16 AM

If RepName = vbCancel Then Exit Sub

Hope this helps,

Russell

Posted by David Holstein on September 29, 2001 7:45 AM

Unfornuatly no, it is hard to understand why INPUTBOX and MSGBOX as so different as it works in MSGBOX code. Thanks anyway

David


Posted by Ivan F Moala on September 29, 2001 11:08 AM

The Inputbox method will return what ever is typed
into it. If canceled it sends a Null string so....

If RepName = "" Then Exit Sub

should work ??

your use of the expression;
if isnull(repname) then exit sub
will not work as expected because the Null value indicates that the Variant contains no valid data. Null is not the same as Empty, which indicates that a variable has not yet been initialized. It is also not the same as a zero-length string (""), which is sometimes referred to as a null string.

Ivan




Posted by David Holstein on September 29, 2001 6:35 PM

Thanks, Works well