WD: Trapping WordBasic ERR=102 After Choosing Cancel ButtonLast reviewed: November 17, 1997Article ID: Q81364 |
The information in this article applies to:
SUMMARYIn Microsoft Word, when you choose the Cancel button in a custom dialog box, you receive the following error message:
WordBASIC err=102 Command FailedTo 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 INFORMATIONAn 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 Subwhere "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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |