Solved

A VERY NEWBIW QUESTION ABOUT INPUTBOXES!!

Posted on 1998-11-04
4
186 Views
Last Modified: 2010-04-30
When I have an Input Box, And press Cancel The Program Crashes, I would like to write an If then Statement to Stop this crashing, So when user clicks on Cancel it doesn't crash but Ends the running program or exits.
0
Comment
Question by:infiniteloop
  • 3
4 Comments
 
LVL 4

Accepted Solution

by:
CraigLazar earned 50 total points
ID: 1443242
Hi infinite loop

HERE is a sample
Put in a command button and see how it works . U will see that if the user presses cancel myvalue is given "" (null) . So then the sample myvalue = "" is then executed . You can also maybe out in there instead of the message box - exit sub - which cancels the subroutine


Private Sub Command1_Click()
Dim Message, Title, Default, MyValue
Message = "Enter a value between 1 and 3"   ' Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "1"   ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)

If MyValue = "" Then
    MsgBox "Cancel"
ElseIf MyValue = 1 Then
   MsgBox "1"
Else
MsgBox "Cancel"
End If


This works
adjust it to use it in your app
If you get stuck Mail me the piece of cose at clazar@softnet.co.za and i will look at it quickly

Cheers mate

Craig
 
0
 
LVL 4

Expert Comment

by:CraigLazar
ID: 1443243
Or what you can do is trap the error that vb is sending u .
What is the error vb sends you when you hit the cancel button ?
craig
0
 
LVL 1

Author Comment

by:infiniteloop
ID: 1443244
Thanks,
0
 
LVL 4

Expert Comment

by:CraigLazar
ID: 1443245
No worries mate
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now