|
|
|
|
|
|
Multiple Apps
|
OK or Cancel InputBox
|
|
Ease of Use
|
Intermediate
|
Version tested with
|
97 and 2000
|
Submitted by:
|
Steiner
|
Description:
|
Differentiate between the OK and the Cancel Button on a regular input box.
|
Discussion:
|
Sometimes you need to differentiate whether the user entered no text and pressed Ok, entered some text and pressed OK, or chose Cancel. This can't be done with just 'If MyString = "" ' because this will be true in two of the cases. There is an undocumented function to see whether any text has been entered into the InputBox. This is just a working example, you'll have to modify the three possible outcomes to your own needs.
|
Code:
|
instructions for use
|
Sub InputBoxNew()
Dim Temp$
Temp = InputBox("Enter something here:", "Inputbox")
If StrPtr(Temp) = 0 Then
MsgBox "You pressed Cancel!"
Else
If Temp = "" Then
MsgBox "You entered nothing and pressed OK"
Else
MsgBox Temp
End If
End If
End Sub
|
How to use:
|
- Copy the code above.
- Open Word, and hit Alt+F11 to open the Visual Basic Editor (VBE).
- Double-click Normal on the left-hand side.
- Choose Insert-Module and paste the code into the window that appears at right.
- Add your own code depending upon the returned value.
- Hit the Save diskette to save the macro in your normal.dot template.
- Close the VBE.
|
Test the code:
|
- Alt+F8 and select InputBoxNew from the list of Macros; click on Run
- Try it with entering some text and clicking OK, entering nothing and clicking OK or just selecting Cancel (no matter whether you've entered text or not), The code as above will confirm your action.
|
Sample File:
|
No Attachment
|
Approved by Anne Troy
|
This entry has been viewed 149 times.
|
|