How to trap errors with an Input Box?

B

Baby Face Lee

Hi everyone,
I've got a situation where three reports are open and there is a macro
attached to the associated toolbar which refers to the 'RunCode' procedure
and a particular function that I've created. This function runs an input box
for each of the three reports in turn, asking the user how many copies of the
report they'd like printed. I've included some blurb in the input box prompt
asking users not to hit the Cancel button as this halts the procedure/macro
resulting in an error message (the macro based 'action failed' message or a
vb 'type mismatch' error).
Is it possible to specify that you don't want a Cancel button with an Input
Box (like you can specify elements of a MsgBox)?
If not, can I trap the errors if a user should still click the Cancel button?

Thanks for your help and advice.

Regards,

Lee
 
A

Al Camp

Lee,
Why don't you just create a small pop up (modal) form that looks just
like an Input Box? You can handle the "input" value, or the OK key just the
way you want.
 
B

Baby Face Lee

Thanks for the reply Al.
I was kinda trying to avoid proliferating more forms but yes I can certainly
do that. I'll wait a little to see if anyone else has any bright ideas
before doing as you suggest.

Lee
 
R

RoyVidar

Baby Face Lee wrote in message
Thanks for the reply Al.
I was kinda trying to avoid proliferating more forms but yes I can certainly
do that. I'll wait a little to see if anyone else has any bright ideas
before doing as you suggest.

Lee

Custom form, as suggested, is probably the best choice - I don't like
the inputboxes much, I must confess, they offer nothing with regards to
validation, which you can easily get through creating a small form -
but
yes you can trap if the user has hit Cancel.

The InputBox function returns a string, and you can actually
differensiate between Cancel and OK with no value by studying the
StrPtr of the returned string

strTest = inputbox("mytest")
if StrPtr(strTest) = 0 then
' cancel is pressed
elseif len(strTest) = 0 then
' no value entered
else
' now there's a selection to be validated
end if

But - I mean - wouldn't it be just the same if the user didn't enter
anything (or removed the default value) and hit OK vs clicking Cancel?
It's very seldom I've had a need to differenciate between those, but
more often between no value (regardless of Cancel or OK with no entered
value) or a value which has to be validated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top