Question on Inputbox function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All,

I have an input box which queries users on how they want to display some
information. A datasheet on screen, or printed report. My code expects the
user to press "D" or "P". Anything else is ignored. The inputbox has OK
and Cancel buttons, I assume by default. My problem is that when the user
clicks on the Cancel button, nothing happens. The prompt remains. So, my
question is how do you programmatically handle clicking the OK or Cancel
button on an input box?

TIA,

Rich
 
If the user cancels, InputBox() returns a zero-length string, so code like
this:

Function TestInput()
Dim strInput As String

Do
strInput = InputBox("Enter D or P")
Loop Until strInput = "D" Or strInput = "P" Or strInput = vbNullString

If strInput <> vbNullString Then
'Do your stuff.
End If
End Function
 
Good Morning Allen,

Thanks very much for the reply. I do understand. However, 1 quick
follow-up question. What happens, or what is returned if user clicks OK?
When I click OK without pressing a key, it appears that a vbNullString is
also returned, just like when hitting Cancel. My test code seems to indicate
that.

Thanks again,
Rich
 
Yes, that's correct: Ok returns a zero-length string if the user input
nothing.
 
Back
Top