Can't Use Arguments to Call Sub When Another Procedure RunningLast reviewed: September 2, 1997Article ID: Q108814 |
The information in this article applies to:
SYMPTOMSIf you run a Microsoft Visual Basic Programming System, Applications Edition, sub procedure that has arguments when another Visual Basic procedure is running, you may receive the following error message:
Can't perform requested operation CAUSEYou cannot call a Visual Basic sub procedure that has arguments if a Visual Basic procedure is running at the time. Take for example a custom dialog box with a control button assigned to a Visual Basic procedure with an argument. If you run the dialog box using the "Run Dialog" toolbar button on the Forms toolbar, you can choose the button and the procedure assigned to that button is run. However, if you show the dialog box from another Visual Basic procedure, and you click the button assigned to the procedure that has arguments, you receive the error message above, because the first Visual Basic procedure is still running. When you run the dialog box from the Visual Basic procedure, the calling procedure is suspended while the dialog box is displayed.
WORKAROUNDAlthough you cannot call a Visual Basic sub procedure that has arguments if a Visual Basic procedure is running, you can do either of the following:
Sub MainMacro()
ArgFlag = 0 'initialize ArgFlag
DoneFlag = 0 'initialize DoneFlag
DialogSheets("Dialog1").Show 'Show it initially
'While the DoneFlag does not equal 1 (which will only occur if the
'DoneButton is clicked), continue to loop through the Subroutine.
Do
If ArgFlag = 1 Then 'if the ArgFlag is set, then
HasArg ("Here is the Argument") 'Arg Sheet1 and
ArgFlag = 0 'reset the ArgFlag
DialogSheets("Dialog1").Show 'Reshow it only after
End If 'having called the procedure
Loop Until DoneFlag = 1 'that hid it
End Sub
Sub DoneButton_Click()
DoneFlag = 1 'set the DoneFlag
DialogSheets("Dialog1").Hide 'hide the dialog box
End Sub
Sub ArgButton_Click()
DoneFlag = 0 'ensure DoneFlag set to 0
ArgFlag = 1 'set the ArgFlag
DialogSheets("Dialog1").Hide 'hide the dialog box
End Sub
Sub HasArg(Arg As String) 'do not assign this macro to any button
MsgBox Arg
End Sub The dialog box will hide itself and a message box will appear with "Here is the Argument" displayed.
REFERENCESFor more information about the Show Method, choose the Search button in Help and type:
dialog boxes: displaying for user input |
Additional query words: 5.00 7.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |