Full Version: Input Box
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
dean411
I have a form that makes an input box appear when a user clicks a particular object. I need some code that will allow the user the click cancel and the input box will dissappear (ie - not run an error) and will not let the user click OK without entering in a value.
NB: some of the input boxes require text while others require numbers and/or dates.
ScottGem
You can't do this with an input box. Use a Popup form instead. Then you can add a Cancel button.
dean411
Is there some code that will perform a loop for the info instead? For example...

Do While IsNull(myVariable)
'A loop to keep prompting the user for myVariable until something is entered
Loop
ScottGem
This is confusing. You want to allow the user to cancel the Input, but then you want to keep prompting them if the value is Null? That's contradictory.
dean411
If the user clicks Cancel, I would like it to ignore the fact that the InputBox was commanded to appear. (Any statement will do). But I don't want the user to be able to click OK without entering a value.

If there is no way to do this, then I'd just like a statement that will not allow the user to do anything unless something is entered in that InputBox.
ScottGem
The problem here is that there is no way to delineate between whether the user just hit Enter without filling in the box or pressed the Cancel key. Both actions return a zero length string. The only way to do that is to set a default value, since pressing Cancel returns a zero length string.

Using a form gives you much greater flexibility.

However, you can easily check if nothing was entered.
CODE
x=""
Do While Len(x) = 0
     x=InputBox("prompt")
Loop

As long as nothing is entered, the message box will continue to appear.
dean411
Thanks, that works.

Is there anything that will work for numbers and date?
[I've already tried using val(myVariable)]
ScottGem
Anything input into an Input box is text. You would have to convert it AFTER its input.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.