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

Mandatory Input Box

Status
Not open for further replies.

LDG1234

Programmer
Jun 26, 2001
120
0
0
GB
Hi guys

Is there a way to make an input box mandatory???

Lloyd Gozzett
Process Developer
 
is it a bound text box? I.e. is it bound to a field in a table?

If so you can set the Required property for the field (in table designer). Once any details are entered for this record, you will have to enter data in this field to move off the record.

If not look into the onClose or onDeactivate events to trigger some code to check if the user has entered anything in the text box. If they haven't cancel the close action, display a msgbox and set the focus to the text box.

HTH,
Col
 
This is in the code that I have written:

ie

Me.Name = InputBox "Enter Name", "Please enter your name"

Any ideas for this?? Lloyd Gozzett
Process Developer
 
so u want to use an input box to populate the text box on your form? Why?

I'd just set the field to Required as I mentioned above as this means Access/Jet handles all this for you.

Just seems a bit weird doing it this way.

Burns
 
This was just an example of the usage.

I have a fairly complex function that is executed on the click of a button.

It calls lots of different functions and then the last piece of code will prompt the user for a reference number for audit purposes. This is where the input box comes into play as this reference number is put at the end of an audit code.

I want this input box to be mandatory - at them moment they can leave it blank which I don't want.

Any ideas?? Lloyd Gozzett
Process Developer
 
strName = InputBox...

if Len(strName) < 1 Then
....
display msgbox
open InputBox again
...
end if

Does this help?

Burns
 
I agree with MontyBurns, in that it does seem an odd way of doing things. On the other hand, &quot;maybe it's me, or maybe it's just Tuesday,&quot; but maybe there's also a reason to want the InputBox. I don't have to know something for it to be true ;> . {I just checked back for new replies before posting, so I see that you do indeed have a reason fo your question :) and were just making the example simpler to make your question clear -- good call!}

Since you want the InputBox, then I can think of one way to &quot;make it mandatory&quot;. The line:
Me.Name = InputBox(&quot;Enter your Name&quot;)
tells me you're working in VBA code. Check the Help file to see what InputBox returns when the user clicks CANCEL. If the constant BADVAL is set equal to that value, and if you also want to make sure that the user enters something other than spaces or an empty string, try something like this:

Code:
    Do
        Me.Name = InputBox(&quot;Enter your name&quot;)
    Loop While ((Me.Name = BADVAL) OR (Trim(Me.Name) = &quot;&quot;))

Then the user won't see anything but the InputBox until they enter something other than BADVAL, spaces, or an empty string. They might get frustrated that the Cancel button doesn't work, but the InputBox will be mandatory :) ! If you want to be a kinder, gentler programmer, you could feed them a message in the body of the Loop, like so:

Code:
    Do
        Me.Name = InputBox(&quot;Enter your name&quot;)
        if ((Me.Name = BADVAL) OR (Trim(Me.Name) = &quot;&quot;)) Then
            MsgBox &quot;You must enter something, and something other than spaces, at that.&quot;
        End if
    Loop While ((Me.Name = BADVAL) OR (Trim(Me.Name) = &quot;&quot;))

You could also store the InputBox message in a string variable, and alter that string variable in the If-Then, instead of displaying a MsgBox; that would save the user another button click, but put the warning in front of them in the InputBox itself. Whether that's a good approach or not, and what wording to use -- these decisions I leave to you :) .

Good luck, Lloyd!
JUST PASSING THRU
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top