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

Determine if user presses cancel on an input box

Status
Not open for further replies.

neemi

Programmer
May 14, 2002
519
GB
I have an input box which the user is required to enter something into.

If they press ok then the value of the input box should be validated to see if something is actually entered. If not then they should get prompted again to enter something.

However if the user presses cancel I want to exit the sub

How can I actually determine which button they ave pressed so I can do this.

I know I can probably create a form quite easily with a text box and two buttons and do all of this there, but I find it hard to believe that an input box which has two buttons already "OK" and "Cancel" will not allow me to deferentiate between wat has been pressed?

Or maybe I just don't know how to do this?

Help and advice appreciated.

Cheers,
Neemi
 
Hi Neemi

According to Access VBA Help, an InputBox will return a zero-length string if CANCEL is pressed.

Regards

Mac
 
Hi Neemi
Even if the user enters something, the return is empty if Cancel is pressed. In other words cancel is the same as entering nothing and pressing ok.
 
You can't test for the button explicitly.
You test for a zero length string being returned.

 
Thanks all for replying.

It is as I thought!

The inputbox is pretty useless really having a cancel and a OK on it.

For what I want to do anyway!

I really couldn't be bothered to create a pop up form to do this, but looks as though I will have to!
:-(
 
neemi, read the help about InputBox and pay attention to the 3rd parameter.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Not a perfect answer, but you could try entering a default. Then the user would have to actually clear the field as well as clicking OK to get the same value as Cancel.
 
Try this
Code:
Private Sub Command0_Click()
    Dim strInput As String
    strInput = InputBox("Enter something:")
    If StrPtr(strInput) = 0 Then
        MsgBox "You pressed cancel!"
    End If
End Sub

________________________________________________________________________
Zameer Abdulla
Visit Me
Children are poor men's riches.
 
PHV, It is "string pointer". that is from VB I learned.

This code was in my code snippets db. and the link available was I checked the link if it is working then I can paste. It was not working. So I pasted the code after testing in access.

Here is the original site from where I got this. I am sorry to say I didn't intent to take credit of the code.

They have changed the site name to Developer.com. I had search with heading by google to get this again.



________________________________________________________________________
Zameer Abdulla
Visit Me
Children are poor men's riches.
 
As a ps, here is a quote from an old (2000) MSDN library:
WARNING: One or more of the following functions are discussed in this article; VarPtr, VarPtrArray, VarPtrStringArray, StrPtr, ObjPtr. These functions are not supported by Microsoft Technical Support. They are not documented in the Visual Basic documentation and are provided in this Knowledge Base article "as is." Microsoft does not guarantee that they will be available in future releases of Visual Basic.
It may no longer be true.


 
So we are playing on a rope that Microsoft can cut any time!!

________________________________________________________________________
Zameer Abdulla
Visit Me
Children are poor men's riches.
 
wow!!!!

wats been going on here....

I have been away from my desk and come back and checked emails etc and all these messages being exchanged bewtween all you.

ZmrAbdulla,
what you suggest sounds good. Will try it and let you know how I get on.

Looks easy when you know the little facts.

thanks for the great response's

Cheers,
Neemi

PS. I am getting to know all your usernames as I keep seeing you threads and replies.

Great community atmos'!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top