Microsoft KB Archive/161646

= TMGR: Open Method Gives No Error If Dialog Box Is Canceled =

Article ID: 161646

Article Last Modified on 8/17/2005

-

APPLIES TO


 * Microsoft Team Manager 1.0 Standard Edition

-



This article was previously published under Q161646



SYMPTOMS
When Microsoft Team Manager's Open method is used without arguments by a macro in another application to display Microsoft Team Manager's Open dialog box, the macro cannot tell from the Open method itself if the Open dialog box was canceled. The Open method returns no useful value, and canceling the Open dialog box produces no trappable run-time error.

For example, when the following macro is run from Microsoft Excel, it returns no error message if the Cancel button in the Open dialog box is clicked: Sub NoErrorIfOpenDlgCanceled Set oTM = CreateObject("TeamManager.Application") oTM.Open   'Displays Microsoft Team Manager Open dialog End Sub

Method 1
This workaround assumes that CreateObject is used to start a windowless instance of Microsoft Team Manager with no open files, and then the Open method is used without arguments to display the Open dialog box.

After the Open method, add another line of code that will produce a trappable error if the corresponding instance of Microsoft Team Manager is no longer running, and add code to trap that error. This works because clicking Cancel in the Open dialog box also closes the corresponding windowless instance of Microsoft Team Manager.

For example, when the following macro is run from Microsoft Excel, it displays a message if the Open dialog box is canceled: Sub StartMtmAndShowOpenDlg Set oTM = CreateObject("TeamManager.Application") oTM.Open             ' Note: MTM closes if Open dialog box is                           ' canceled. On Error Resume Next ' Start error trapping. oTM.Visible = True   ' Causes trappable error if MTM is not running. If Err > 0 then MsgBox "You canceled the Open dialog." End End IF    On Error Goto 0       ' End error trapping. End Sub

Method 2
This workaround assumes that GetObject is used to control an existing instance of Microsoft Team Manager that already has an open file, and the Open method is used without arguments to display the Open dialog box.

Add a line of code before the Open method to save the current file path and name, and then add code after the Open method to compare the new current file path and name with the original. If they are the same, then the Open dialog box must have been canceled.

For example, when the following macro is run from Microsoft Excel, it displays a message if the Open dialog box is canceled: Sub ShowOpenDlgWhenSomeFileAlreadyOpen Set oTM = GetObject(, "TeamManager.Application") SavePathAndName = oTM.File.Path       ' Save current path and name. AppActivate oTM.Window.Caption        ' Switch to MTM so Open ...     oTM.Open                               ' ......dialog box can be seen. AppActivate Application.Caption       ' Switch back to MS Excel. If SavePathAndName = oTM.File.Path Then MsgBox "You canceled the Open dialog." End If  End Sub



STATUS
This behavior is by design.



MORE INFORMATION
All of the macros in this article are assumed to be run from another application, such as Microsoft Excel or Visual Basic.

Open Method with Arguments
It is possible to use the Open method with arguments to open an existing team file, without displaying the Open dialog box.

For example, when the following macro is run, it saves the current team file (if there is one open) and attempts to open the specified team file: Sub SaveCurrentFileAndOpenAnother Set oTM = GetObject(, "TeamManager.Application") oTM.Open Yes, "C:\MyFiles\File1.mtp" End Sub In this macro, an error occurs if Microsoft Team Manager is not already running. An error also occurs if the specified file is already open on another computer or in a different instance of Microsoft Team Manager on the same computer, although Microsoft Team Manager does not display a message saying the file is already in use. No error occurs if the file is already open in the same instance (referenced by oTM).

Using GetObject to Open a File
It is possible to use GetObject to open a team file without using the Open method.

For example, when the following macro is run from Microsoft Excel, it starts a new instance of Microsoft Team Manager and opens the specified file, assuming the file exists and is not already open: Sub StartMtmAndOpenFile Set oTM = GetObject("C:\MyFiles\File1.mtp") End Sub In this macro, an error occurs if the file does not exist or if the file is already open on another computer. If the file is already open on another computer, Microsoft Team Manager first displays a message saying that the file is currently in use, and after that message is closed, the macro error occurs.

There is no error if the file is already open on the same computer. oTM refers to that instance of Microsoft Team Manager. GetObject does not start a new instance.

