Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Monday, August 18, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: How do I stop the close action of a form
Laura
Posts: 13
 
How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Jan 08 2:55 PM
After a user clicks on the X on the top right of a form, I need to find out if the user wants to save first. If there is invalid data, how do I stop the close action (after data validation) and keep the form in view?

[Reply][Quote]
Jason Huber
Posts: 77
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Jan 08 10:01 AM
Not sure if you are asking if they click the X specifically, but I see a couple of things.

You can use FormClose and set AXFormCloseQuery = false

I normally use validate and check to see if they user pressed OK before validating.
if modalResult = vbOK then
'validate
end if

But if they user presses X they normally dont want to save. Same with cancel, so I have never actually tried it on pressing X - it is just a useability thing, but your business and users might be different. So try onclose event and axformclosequery (that looks right)
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Jan 08 4:21 PM
Use the OnCloseQuery event of the form. Create a function along the following lines:

Function AXFormCloseQuery(Sender)
Dim Confirm
Confirm = MsgBox("Close Form?", vbYesNo, "Close Form")
If Confirm = vbYes Then
AXFormCloseQuery = True
Else
AXFormCloseQuery = False
End If
End Function

Cheers
Phil
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Jan 08 11:26 PM
Jason, i was just going to mention that clicking the X *does* fire the axformclosequery event and you can stop it from closing by returning false.
[Reply][Quote]
Jason Huber
Posts: 77
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Jan 08 7:02 AM
Thanks Ryan. I wasnt sure and I wanted to be honest about that. I am teaching a LAN class this week, so I will be sure to explore it with them a bit as well.

It is an interesting scenario because even in my closequery routine I only validate if they pressed OK, so X wouldnt get validated. If your users expect X to save data or warn them, I guess you better not just look for OK like I usually do.
[Reply][Quote]
Laura
Posts: 13
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Jan 08 9:02 AM
Thank you everyone for your suggestions. Unfortunately, I had already tried setting AXFormCloseQuery to False but it doesn't work.

Function AXFormCloseQuery(Sender)

If MsgBox("Do you want to save first?", vbYesNo, "Warning") = vbYes Then
AXFormCloseQuery = False
btnSaveClick(Sender)
Else
AXFormCloseQuery = True
End If

End Function

The btnSaveClick code is validation code that triggers when the users clicks on the Save button. The form remains in view if there is invalid data.

Also, the AXFormCloseQuery does not fire when I click on the X. I tried setting it for the event in the Properties box, but that still didn't work. The only way I'm getting the AXFormCloseQuery to fire is if I specifically call it in AXFormClose, but once it goes through the code there, the form closes.

I have another question since I can't seem to get this to work correctly. Is there anyway I can disable the X, so that the user must use either the Save or Cancel button?
[Reply][Quote]
Jason Huber
Posts: 77
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Jan 08 9:22 AM
I just checked with Outlook and it performs the action as you suggest. If I hit X it asks me to save...

I will get into this with the class by the end of the day and ask them to post a response. unless someone else does first...
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Jan 08 3:05 PM
Hi Laura,

I just tested this and it worked fine for me. Here's the steps for a simple test:

1) Create a new form. I selected a Manage form since I wasn't going to use any binding
2) Create a way to launch the form (I placed a button on the toolbar)
3) Place a checkbox on the new form named "checkbox1"
4) Add the following code to the AXFormCloseQuery event:

Function AXFormCloseQuery(Sender)

If CheckBox1.Checked Then
AXFormCloseQuery = False
Else
AXFormCloseQuery = True
End If
End Function


5) Launch the form and test it. If the checkbox is checked, the form will not close - whether you click the OK or Cancel buttons and even if you click the "X".

I would try this simple test and then work backwards for your form you need to add this to. Hope this helps.

-Ryan
[Reply][Quote]
Laura
Posts: 13
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 15 Jan 08 11:07 AM
Ryan:

I tried and tried but the AxFormCloseQuery is not firing when I click on the X, Cancel or anything. It goes straight to AXFormClose.

Since I can't get this to work, is there anyway I can disable the X so that the user must click on the Save or Cancel button?

Thanks for all your help.
[Reply][Quote]
Steve Robertson
Posts: 146
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 16 Jan 08 4:10 AM
Hi Laura,

I don't think that you can disable the X.

The only way that I can see that the AXFormCloseQuery Function is not called is if the AXFormCloseQuery Function in the script has not been linked to the Form's OnCloseQuery event.

If the AXFormCloseQuery Function is not linked to the Form Event it does not prevent the form close even if you set it to False.

So I would first check that the Form's event for OnCloseQuery is set to the AXFormCloseQuery.

Hope this helps,

Steve

[Reply][Quote]
Laura
Posts: 13
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 16 Jan 08 4:12 PM
Hi Steve,

The OnCloseQuery event is linked to the AXFormCloseQuery. I am at a loss as to why it's not firing. We are using v6.2.6. Is there a possibility that this is not working in this version?

Thank you for your input. I appreciate all the help/suggestions I have received.
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 16 Jan 08 4:54 PM
Hi Laura - the fact that it seems to work for everyone apart from you must be getting really annoying

Did you try Ryan's suggestion of creating a new very simple form and seeing whether that works? Then at least we narrow down the problem to just your form (and not some generic SLX issue).

Do you know for a fact that the event is not firing? You could try the following to confirm this 100%

Function AXFormCloseQuery(Sender)
MsgBox "AXFormCloseQuery"
End Function

P
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 16 Jan 08 5:07 PM
Maybe verify that the event is still wired up? Could it be that the sub is no longer selected in the dropdown for the event in the form's properties?
[Reply][Quote]
Matt Dockins
Posts: 159
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 12:33 AM
Laura I've encountered what you are experiencing where AXFormCloseQuery is not called from the X close event.

You can suppress the X, depending on how you open the form, by changing the windowstyle property. You can do this by launching the form using Application.Mainviews.Addex and changing the WindowStyle property (argument #2) to (I think) 0 - You can also set the windowstyle property when launching the form in other ways but its midnight and this one is the first that came to mind.

It may look a bit odd to in your window however as that removes all the buttons AND the border around the form, so you just have the form detail floating in the middle of your screen - which means it can't be moved or closed until they click on one of your buttons with a modalresult. There are other options to try (windowstyle is an integer correlating to a vb constant) but I think 0 is the only one that will remove the X.
[Reply][Quote]
Steve Robertson
Posts: 146
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 5:49 AM
Laura,

Another thing to check is there more than one function called AXFormCloseQuery in the script on your form?

I have tested if there is more than one function with the same name - it manages to select the first one that was added to the script, even if you change the order of the functions. So in the case I was testing I had the msgbox script in the second created AXFormCloseQuery function and the msgbox does not fire.

Sorry - but I have tested in 6.2.6 and 7.2.1 but all seems fine here, using a data bound and a manage form. Only way that I have replicated so far is that the AXFormCloseQuery is not linked to the OnCloseQuery and there being 2 functions in the script called AXFormCloseQuery.

Is there anything "Special" about your form?

Hope to be of some help!

Cheers,

Steve

[Reply][Quote]
Laura
Posts: 13
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 4:02 PM
I just tried Ryan's suggestion to create a new simple form and IT WORKED !!. It's just not working on the form I want to make that change on. I'm doing exactly the same thing on this form but that event is not firing. I've double/triple checked everything. I only have one AXFormCloseQuery function and the OnCloseQuery event is linked to it.

I'll have to investigate further to see what's cauisng it not to fire.

Thanks again to all.
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 4:55 PM
This is a somewhat tedious way of proceeding, but it may help you.

Just before you launch the form, set Tools/Options/Other/Debug to 'Always'.

Assuming you have VS or MS Script Debugger installed, everything you do from then on will go into debug mode.

Then launch the form. The debugger will launch - press F5 repeatedly to get through any code that executes when you open the form. Control will eventually pass back to the form - then click on X to close and you will go back into debug mode. From there you can step through exactly what code is executed when you close the form.

Tip - turn off debugging for yourself by logging into the Administrator client and changing it there - rather than F5'ing through the Sales client with debug = always turned on.

PP
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 5:01 PM
Quote:
Originally posted by Phil Parkin

Just before you launch the form, set Tools/Options/Other/Debug to 'Always'


You can also add the "Stop" keyword to your script which will cause it to launch the debugger at that point as well.

-Ryan
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 5:04 PM
But if the event isn't firing, where do you put it?
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 5:06 PM
Quote:
Originally posted by Phil Parkin

But if the event isn't firing, where do you put it?


Good point, Phil (Although I would just put it in the open event)
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 5:18 PM
OK - that is better, I agree.

Thinking just one step further - why not create a new button on the form whose OnClick event runs STOP? Then you avoid almost all the pain of stepping through spurious code.

Phil
[Reply][Quote]
Rohan Verghese
Posts: 40
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 5:19 PM
Have you tried removing the function? Remove it, save it in Notepad, and remove the link between the function and event. Save the form and run it. Then paste the function back in and re-add the link.

Maybe the link is damaged. Clearing it and rebuilding it might get it to work again.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 5:24 PM
Quote:
Originally posted by Phil Parkin

Thinking just one step further - why not create a new button on the form whose OnClick event runs STOP? Then you avoid almost all the pain of stepping through spurious code.


Now that is a great idea

-Ryan
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 17 Jan 08 5:29 PM
Nearly - except it doesn't work - just tried it

Created a blank manage form with a debug button on it. Also tied a MsgBox to the Cancel button.

Click on debug - fires up debugger - F5 to return control to the form. Then click on Cancel - MsgBox appears without debugging.

PP
[Reply][Quote]
Laura
Posts: 13
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 23 Jan 08 10:47 AM
Since the X and the Cancel button work the same way, I created a Sub for the OnClick event of the Cancel button and put a Stop there. A short background on this form.... This form is created and opens up after I right-click on a grid in another form and select an option from the Popup menu (Add, Edit).

The following is happening when the Debugger starts at that Stop. After the debugger gets out of the btnCancelClick code, it goes to the Add function in the first form and stops at a line of code 'CancelAdds' which calls another sub to delete stuff from tables. It then goes back to AXFormClose on the second form (the one where I clicked the Cancel button).

I had also tried what Rohan suggested but that didn't help either.

Laura
[Reply][Quote]
Frank
Posts: 25
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 24 Jan 08 9:56 AM
Hi
I've the same problem! My Form will not fire the event OnCloseQuery If I clicked X.

But If I testing this Mystic event "OnCloseQuery" at the SalesLogix Form "Add New Contact Account".
I put the command STOP in this event "OnCloseQuery", release this only for developer.
If it open this Form and I clicked on X, then the event will be work funy.

I've use this Form, I drop all Code and release it again then I will not work!
What is here the problem?

brgds Frank Kress

[Reply][Quote]
Frank
Posts: 25
 
Re: How do I stop the close action of a formYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 24 Jan 08 10:03 AM
Sorry, I've type a mistake in my english.
I Know my english is not very well, but here are the right on....

Mistake at the row: I've use this Form, I drop all Code and release it again, then (not I) it will not work!

brgds Frak Kress


Quote:
Originally posted by Frank

Hi
I've the same problem! My Form will not fire the event OnCloseQuery If I clicked X.

But If I testing this Mystic event "OnCloseQuery" at the SalesLogix Form "Add New Contact Account".
I put the command STOP in this event "OnCloseQuery", release this only for developer.
If it open this Form and I clicked on X, then the event will be work funy.

I've use this Form, I drop all Code and release it again then I will not work!
What is here the problem?

brgds Frank Kress

[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 8/18/2025 3:34:36 PM