Using the input box command...

  • Thread starter Thread starter Brad Pears
  • Start date Start date
B

Brad Pears

I am using the inputbox function to get a REQUIRED entry from the user. I
want them to be forced to enter something in here - or be able to press
cancel if they get there accidentally...

So, I have code that will force them to make an entry, but how do I check to
see if cancel was pressed to get them out of the loop?? The following code
forces them to make an entry regardless of the fact that they may have
pressed the cancel button...
Here is the code...

strReason = ""
Do While IsNull(strReason) Or strReason = ""
strReason = InputBox(strMessage, strTitle)
Loop


Thanks,

Brad
 
I don't believe this is possible with the InputBox function. You can do it
with a form. Open the form using the acDialog option, so that the code that
opens the form waits for the form to be closed or hidden before continuing.
Have your OK button hide the form (Me.Visible = False) and your Cancel
button close the form. When the user clicks either button, the code that
opened the form will continue. You can now check whether the form is open
(If CurrentProject.AllForms("NameOfForm").IsLoaded Then). If the form is not
loaded, the user clicked the Cancel button. If the form *is* loaded, the
user clicked the OK button, you can retrieve the data from the form and then
close it.
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Back
Top