WD: Trapping WordBasic ERR=102 After Choosing Cancel Button

Last reviewed: November 17, 1997
Article ID: Q81364
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Word for the Macintosh, versions 6.0, 6.0.1

SUMMARY

In Microsoft Word, when you choose the Cancel button in a custom dialog box, you receive the following error message:

   WordBASIC err=102
   Command Failed

To Word, the Cancel button indicates a run-time error; therefore, Word halts execution of the macro. You can trap this error with an On Error command in your macro if you want to suppress the message and let the macro continue.

An alternative method of trapping this error is to call the function form of the dialog box. When you choose the Cancel button, a value of 0 (zero) is returned instead of a WordBasic error.

MORE INFORMATION

An error trap statement within a sample section of macro code resembles the following example:

   Sub Main
   On Error Goto ExitMacroDialog
   Begin Dialog UserDialog
   '
   '
   End Dialog
   '
   '
   ExitMacroDialog:
   '
   '
   End Sub

where "ExitMacroDialog" is a label somewhere beyond the dialog statement for the dialog box.

The lines that include an apostrophe indicate there may be more macro code between the given statements. If you receive the WordBasic error 102 after putting the error trap into the macro, check to make sure the label is valid and that the On Error statement appears in order before the Dialog statement.

Alternative Error Trapping Method 1:

The alternative method for trapping the Cancel button in a custom dialog box is to call the function form of a dialog box. If you trap an error with this method, the "On Error Goto" statement is not used. The following is a sample macro that creates a custom dialog box using the function form of the dialog box. This method returns a value of 0 (zero) if you choose the Cancel button instead of halting the macro and generating the WordBasic error 102.

   Sub Main
   Begin Dialog UserDialog 320, 124, "Word for Windows 2.0"
    TextBox 12, 30, 160, 18, .TextBox1
    TextBox 13, 83, 160, 18, .TextBox2
    Text 18, 10, 92, 13, "First Name :"
    Text 17, 60, 92, 13, "Last Name :"
    OKButton 205, 41, 88, 21
    CancelButton 205, 65, 88, 21
   End Dialog
   Dim dlg As UserDialog
   '
   Select Case Dialog(dlg)
   Case - 1
    MsgBox "Rest of Macro..."
   Case Else
    MsgBox "Exit Macro. Choose OK Button."
   End Select
   '
   RestofMacro:
    MsgBox "Rest of Macro..."
   End Sub

Alternative Error Trapping Method 2:

This method also avoids the use of the "On Error Goto" statement. The "If" statement will run only if the OK button is clicked.

Sub Main
 Begin Dialog UserDialog 320, 124, "Word for Windows 2.0"
 TextBox 12, 30, 160, 18, .TextBox1
 TextBox 13, 83, 160, 18, .TextBox2
 Text 18, 10, 92, 13, "First Name :"
 Text 17, 60, 92, 13, "Last Name :"
 OKButton 205, 41, 88, 21
 CancelButton 205, 65, 88, 21
 End Dialog
 Dim dlg As UserDialog

 If Dialog(dlg) then
  MsgBox "Rest of Macro…"
 End If
End Sub


REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, pages 158, 173-174

Kbcategory: kbusage kbmacro KBSubcategory:


Additional query words: winword2 6.0 6.0a 6.0c 1.x 2.0 word6
6.0.1 word7 winword 7.0 word95 winword 2.0a 2.0a-CD 2.0b 2.0c
macword
Keywords : winword winword2 word6 word7 word95
Version : WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a, 6.0c,7.0,7.0a; MACINTOSH:3.0,3.01,3.02,4.0,5.0,5.10,6.0,6.0.1,6.0.1a;


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.