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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input Box Cancel button

Status
Not open for further replies.

balistikb

Technical User
Nov 12, 2002
177
0
0
US
How could I use the cancel button in an Input Box to cancle out of the form and close?
 

Give this test prog a try, it may help you understand how to accomplish what you want
[tt]
Option Explicit

Private Sub Form_Load()
If InputBox("Your Prompt", "Your Title", "Your Default") = "" Then End
End Sub
[/tt]

Good Luck

 
That is if I want to exit when they enter nothing right? If it is that will not work.
 

Have you tried it? If user presses cancel button (How could I use the cancel button in an Input Box to cancle out of the form and close?) it will work. Go ahead and give it a try. If you are complaining that it ends the program then replace end with unload me, or if you are stating that they click on ok with a default there then just remove the default. Go ahead and give it a try, it may help you understand how to accomplish what you want

GOOD LUCK!

 
If you want to UNLOAD the form, after the user cancels the InputBox, you have to do Unload Me or whatever you do to cancel the form. If you have code in a cancel button on your form, try this:

Private Sub Form_Load()
'......
TheValue = InputBox("Prompt", "Title", "Default")
If TheValue = "" Then
Call CancelButton_click
exit sub
End If

'do stuff with TheValue
End Sub
Hope that helps.
 
Here is the code I put it in a few areas and I get an error. I think I am missing something. Where would you put it?


Public Sub WrongValue()

On Error GoTo ErrorHandler
ContinueHere:
prompt$ = "Please enter class number."

Do
SearchStr$ = InputBox(prompt$, "CLASS NUMBER")
datClassEval.Recordset.Index = "PrimaryKey"
datClassEval.Recordset.Seek "=", SearchStr$

Loop While datClassEval.Recordset.NoMatch

txtLocator.Text = datClassEval.Recordset![LocNumber]
txtName.Text = datClassEval.Recordset![CLASS_NAME]
txtTrainer.Text = datClassEval.Recordset![REGISTRAR_INSTRUCTOR]
txtDate.Text = datClassEval.Recordset![Date]
txtHours.Text = datClassEval.Recordset![CLASS_HOURS]
Exit Sub

ErrorHandler:
If Err.Number = 3421 Then
MsgBox "You have entered a class number that is not correct. Please re-enter a correct class number", vbCritical
Resume ContinueHere
Else
MsgBox Err.Number & ": " & Err.Description 'this Catches other errors
Resume ContinueHere
End If

End Sub
 

Try this...
[tt]
Do
SearchStr$ = InputBox(prompt$, "CLASS NUMBER")
If Trim(SearchStr$) = "" Then Exit Sub
datClassEval.Recordset.Index = "PrimaryKey"
datClassEval.Recordset.Seek "=", SearchStr$
Loop While datClassEval.Recordset.NoMatch
[/tt]

good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top