ID: Q108814
The information in this article applies to:
If 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
You 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.
Although 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:
-or-
1. Enter the following in a new module sheet:
Public DoneFlag As Integer, ArgFlag As Integer
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
2. Insert a new dialog sheet and make sure it is named "Dialog1", without
quotes.
3. Add two new buttons to the dialog sheet.
4. Change the text of one button to "PassArg", without quotes, and assign
the ArgButton_Click macro to this button.
5. Change the text of the other button to "Done", without quotes, and
assign the DoneButton_Click macro to this button.
6. Run the MainMacro subroutine.
7. The dialog box will appear - click the "PassArg" button.
The dialog box will hide itself and a message box will appear with "Here is the Argument" displayed.
8. Click OK in the message box.
The dialog box reappears. This will repeat itself as long as you click the "PassArg" button on the dialog box.
9. Click the "Done" button to dismiss the dialog box and stop the MainMacro
subroutine.
For 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
Keywords : kbprg
Version : 5.00 5.00c 7.00
Platform : WINDOWS
Last Reviewed: May 19, 1999