Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
New Member
Posts: 22
Registered: ‎02-15-2010

Can't close a Mainview using "application.mainview.close"...

Hi there,
I'm experiencing some problems doing some customizations that I've never done before. I need to have a form opened that is linked to a custom table. I must allow the user to move from this form to main views like accounts, contacts, etc. So this form could not be a modal one. (Similar as when you are on a contact, and click on the account's name link control)
Well, whenever I click outside this form or move to a main view (hitting the accounts navbar button for example), it automatically closes (remember it shouldn't be modal), so I must do a main view instead, containing this form on the detail part to solve this problem.
Doing that, the user can move trough views without problems, but now I encounter a new dilemma. - I'm not able to close the view correctly.
I've created a button on the form, that calls a script, and if that script meets some criteria, the main view containing the form must be closed, (or refreshed with a new recordID), so inside this script I move through the mainviews, and make a application.mainviews.post, then a mainview.refresh (so it does not ask for saving changes) and then a move to a new ID (mainview.getviewforrecord) or close the view (using mainview.close), but this (close the main view) don't seem to works, and the main view is posted and refreshed but remains opened.
How should I achieve this? Can I achieve this using forms instead of main views, or are they always close when they lost the focus? How do I force the system as if I hit the "X" on the top right corner? It's possible to close a main view from outside the main view code as I'm trying to do (close the main view from within the script)?
Many thanks in advance for any help you can provide.
Best regards.

Silver Contributor
Posts: 835
Registered: ‎03-24-2009

Re: Can't close a Mainview using "application.mainview.close"...

you open a main view up as an independent window.....called from a script.....the window closes itself and returns to the calling script on a mainviewobject.showmodal.

 

Ryan Farley posted this on his superb forum a few years ago:

 

I know I've closed modeless MainViews before by setting the ModalResult to mrOK. Not sure why it isn't working for you. You could always try using the ActiveView reference to see if that works:

Application.MainViews.ActiveView.Close



If that doesn't do it, here's one way that will work for sure. You can pass a reference of the MainView object itself to the MainView. Then you can just call it's close method to close the form. Here's how you will do that.

In the MainView, add the following OUTSIDE of any Sub. Just at the top of the script somewhere. You want this to be global in scope to the form so it can't be in any subs of functions.

Dim MainViewReference



Now in the code that invokes the MainView, you'll do this:

Dim mv

Set mv = Application.MainViews.Add("System:MyForm", 2, False)
Set mv.DetailsView.Script.MainViewReference = mv
mv.Show



In the MainView, the variable MainViewReference will contain a reference to the MainView object itself that you created to launch the form. You can use that now when you want to close the MainView by calling it's close method:

' close the main view...
MainViewReference.Close

RJ Samp