Closing / Ending a mxd

1350
19
01-07-2013 05:14 AM
MichelleCouden1
Occasional Contributor III
I have a dialog box with a cancel button on it. I want the whole mxd to close down when they click on the Cancel button. My button is written as such :

Private Sub cmdCancel_Click()
End

End Sub

What do I type to close the mxd???
0 Kudos
19 Replies
MichelleCouden1
Occasional Contributor III
The mxd has loaded. You open an mxd to get the dialog box. So hitting the cancel button should close the mxd that is open at that time. Called UserForm1.mxd!!!
0 Kudos
MichelleCouden1
Occasional Contributor III
I am trying to understand. I am new to ArcObjects the language is different then VBA. When you open an mxd to get the dialog box, I am not understanding why when you hit the cancel button it can't close that mxd.
0 Kudos
NeilClemmons
Regular Contributor III
I don't know how to explain it other than to repeat what I've already said.  The OpenDocument event fires when a document is opened.  Inside this event, you are calling your form.  You cannot close ArcMap or load another document from this form because ArcMap is already in the process of opening a document.  I have tested this and each time I try it I get an Access Denied error.  If you want to close ArcMap or load another document then you will have to do it from somewhere other than the OpenDocument event.

Also, ArcObjects is not a language.  The language you are using is VBA.  It's important to tell others this when asking a question because the vast majority of the people on this forum do not use VBA.  They use a .NET language, C++ or Java.  How you do things can vary greatly depending on your programming environment so telling people what environment you're using will get you a correct answer much faster.
0 Kudos
MichelleCouden1
Occasional Contributor III
I got it. Thanks again for your help!!!! Hey, since your experienced in ArcObjects could you help me with another button code. Really, I just need proper command to get to a folder than open an mxd. I am using If then statements such as this :

Dim cboStations As String
'If cboStations = "Annual" Then gotofolder "K:\TASS\4_MAPPING_DATct_Maps\2012"
'Else
'gotofolder "K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\Urban_Maps"

'Dim districts As String
'Dim cboDistrict As String
'If cboDistrict = "Abilene" Then getmxd "K:\TASS\4_MAPPe\Abilene_Base_Map.mxd"
'Elif
'cboDistrict = "Amarillo" then getmxd "K:\TASS\4_ps\2012\Amarillo"
Am I on the right track??
0 Kudos
BillSaunders
New Contributor
I am having a similar problem to the one documented in this thread.  I have an inherited VBA .mxd that runs in both ArcGIS 9.3.1 and 10.0.  The .mxd uses a form that includes an Exit button.  In 9.3.1, selecting the Exit button shuts down ArcMap immediately (which is what we want).  In 10.0, the Exit button leads to the dialog box "Save changes to xxx.mxd?"  This may be minor, but I have a number of staff users who have some trouble spelling GIS, and saving changes would lead to unwanted text boxes included in subsequent iterations of the product layout (i.e. without me having to go in and clean them up).  Everything else about this .mxd works the same in 9.3.1 and in 10.0.  Wondering what else I need to do in the 10.0 version of the .mxd to get it to shutdown immediately without the dialog box.  Here is the code for the Exit button in the form:

Private Sub cmdExit_Click()
'   Code to shutdown application
    Dim pApp As IApplication
    Set pApp = Application
 
'   Do not save changes
    pApp.Shutdown
    SendKeys "n"
End Sub

Thanks in advance.
0 Kudos
NeilClemmons
Regular Contributor III
Before calling Shutdown, try calling IDocumentDirty2.SetClean.
0 Kudos
BillSaunders
New Contributor
Thanks for the quick reply.  I changed the VBA code as follows:

Private Sub cmdExit_Click()
'   Code to shutdown application

    Dim pApp As IApplication
    Set pApp = Application
 
    Dim pDirty As IDocumentDirty2
    pDirty.SetClean
   
'   Do not save changes
    pApp.Shutdown
    SendKeys "n"
End Sub

But the mxd gives me a Runtime Error 91 when I select the Exit button and is hanging on the .SetClean command.  Did I not implement this into VBA correctly?
0 Kudos
NeilClemmons
Regular Contributor III
You have to instantiate the variable pDirty before you can use it.
0 Kudos
BillSaunders
New Contributor
DUH.   Thanks.  That works great.  Now, for my info, why is this required in ArcGIS 10.0 and not in 9.3.1?
0 Kudos
NeilClemmons
Regular Contributor III
ESRI fixes a lot of things behind the scenes with each version release.  I can't say why they made this change in particular but I would guess it was an application design decision.  They realized calling Shutdown didn't prompt to save changes so they changed it so that it does (unless you clear the dirty flag). Again, that's just speculation.
0 Kudos