ID: Q81364
The information in this article applies to:
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.
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.
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
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
"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 word6 winword2 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;
Last Reviewed: November 18, 1997