Closing / Ending a mxd

1353
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
NeilClemmons
Regular Contributor III
If you want to unload the mxd then call IApplication.NewDocument.  If you want to close ArcMap itself then call IApplication.Shutdown.
0 Kudos
MichelleCouden1
Occasional Contributor III
Not to sure how to program that!!

Private Sub cmdCancel_Click()

IApplication.Shutdown
End

End Sub

This is how it is now and it does not shutdown the mxd..  All it does is close down the box!!!!
0 Kudos
NeilClemmons
Regular Contributor III
IApplication is the interface you need to use.  You will need to declare a variable of that type and set it to an instance of the ArcMap application.  Once you've done that you can call the methods you need.  How you do this depends on your environment so I'll leave that up to you.
0 Kudos
MichelleCouden1
Occasional Contributor III
Can't do that! If you notice it is for a command button in a dialog box program. When they open the mxd a dialog box pops up in order for them to answer some questions. On the box is a cancel button, when they hit the cancel button it needs to close the mxd. So I need the code to shut down an mxd when the cancel button is pushed on the dialog box.


Private Sub cmdCancel_Click()


IApplication.Shutdown
End

End Sub
0 Kudos
NeilClemmons
Regular Contributor III
You always have a way to get a reference to the ArcMap application.  If you're implementing an extension then it's passed into the Startup method.  If you're implementing a command or tool then it's passed into the Create method.  Addins have something similar but I don't work with them so I don't know it off the top of my head.  In VBA, it's a built-in environment shortcut named Application.
0 Kudos
MichelleCouden1
Occasional Contributor III
So I would go to ThisDocument and put this code underneath my OpenDocument?? Like Such :

Private Function MxDocument_OpenDocument() As Boolean
     
      Dim frm As frmMapSetUp
      Set frm = New frmMapSetUp
      frmMapSetUp.Show
     
End Function

Private Sub cmdCancel_Click()


IApplication.Shutdown
End

End Sub

Is this right??
0 Kudos
KenBuja
MVP Esteemed Contributor
If you're working with an Addin and you want to close ArcMap, then use the line

My.ArcMap.Application.Shutdown()
0 Kudos
NeilClemmons
Regular Contributor III
No, that is not correct.  First, you should have stated that you're using VBA to begin with so that someone trying to answer your question would know what environment you're working in.  As I said in my last post, VBA has a built-in shortcut named Application.  So the code would be:

Application.Shutdown()

However, since you're calling your form from ArcMap's OpenDocument event you will not be able to close ArcMap or load another document because ArcMap is already in the process of opening a document.  You can only do these kind of things after the document has been loaded.
0 Kudos
MichelleCouden1
Occasional Contributor III
Sorry, didn't think I had to state I was using ArcOBjects because I went into the ArcObjects area of the forum. Sorry about that! So since I have open document in running in this document there is no way to program the cancel button to shut it down. Right!! Would I maybe put the programming of the cancel button in ThisDocument under the open document programming. Would that work? And use what you gave me.
0 Kudos