Prevent OK Button from Closing Form?

1214
5
Jump to solution
03-22-2012 08:41 PM
DanikBourdeau
New Contributor III
I need to prevent the OK button from shutting the form or I need a way to get rid of the OK button all together.  Anyone have any ideas?

Here's the scenario.  The field teams collect data for multiple artefacts at one location.  I have it setup so that they can push a button and the data is written to a shapefile and the form is refreshed without closing so they can keep entering the next artefact without opening the form all over again.  The problem of course is that they on occasion hit the ok button instead which closes the form and then they have to re-open it.

The problem I'm facing is that I can't use any of the onValidation  calls because technically everything should pass validation in order for the data to get written.  I can't figure out how to get everything to pass validation then write all the data and then prevent the form from closing. Any help would be appreciated.

Thanks,
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RolfBroch
Occasional Contributor II
Suggestion:

Create a variable g_bAlreadyOpened which is set to false before the form is opened.

In the onload event you check if this variable is false, if so, you do all the initial stuff and set the g_bAlreadyOpened to true

Otherwise you skip all the stuff that is done in the onload routine

Use the onunload event to check if g_bAlreadyOpened is true, if so, open the form with the .Show method

In order to actually close the form you need to set g_bAlreadyOpened to false in the OnCancel event

Rolf

View solution in original post

0 Kudos
5 Replies
MatthewMurray1
New Contributor III
Danik,

Perhaps I am missing something but couldn't you jsut add Applet.Forms("FORM").show(); to the onOk event for the form this would just open the form again??

This would essentially make it as if the form never closed..
0 Kudos
DanikBourdeau
New Contributor III
Hey Matthew,

Thanks for the suggestion.  I had thought of doing this and I think at one time I did have it setup up this way but unfortunately it won't really work now.  I have quite a lot of things happening during the onLoad event and forcing the form to reopen all the time would probably mess things up.

I was hoping that someone had a magic trick up their sleeves to prevent the OK button from closing the form.

If I can't find a way I may have to use your suggestion and rework my code; Pain.

Thanks,
0 Kudos
RolfBroch
Occasional Contributor II
Suggestion:

Create a variable g_bAlreadyOpened which is set to false before the form is opened.

In the onload event you check if this variable is false, if so, you do all the initial stuff and set the g_bAlreadyOpened to true

Otherwise you skip all the stuff that is done in the onload routine

Use the onunload event to check if g_bAlreadyOpened is true, if so, open the form with the .Show method

In order to actually close the form you need to set g_bAlreadyOpened to false in the OnCancel event

Rolf
0 Kudos
DanikBourdeau
New Contributor III
Hey Rolf,

Great Suggestion, it worked beautifully.  I did have to make a few changes to the code to ensure variables maintained their values once the form was restarted but it all seems to be working good.

The field teams will be happy!

Here's a short snippet of how I got it to work:
Option Explicit
Dim g_bAlreadyOpened, XCoord, YCoord

g_bAlreadyOpened = False

Sub OnLoadForm
   If g_bAlreadyOpened = False Then
      XCoord = Application.GPS.X
      YCoord = Application.GPS.Y
      g_bAlreadyOpened = True
   End If
   Applet.Forms("T1").Pages("Page1").Controls("Easting").Value = XCoord
   Applet.Forms("T1").Pages("Page1").Controls("Northing").Value = YCoord
End Sub

Sub OnUnloadForm
   If g_bAlreadyOpened = True Then
      XCoord = Applet.Forms("T1").Pages("Page1").Controls("Easting").Value
      YCoord = Applet.Forms("T1").Pages("Page1").Controls("Northing").Value
      Applet.Forms("T1").Show
   End If
End Sub

Sub OnCancelForm
   g_bAlreadyOpened = False
End Sub


When the form first starts up controls 'Easting' and 'Northing' are populated based on their respective GPS coordinates but since the field teams frequently change the values (because the don't want to stand in a river for example) I had to make certain that any changes would follow through when the form is re-initialized from the OnLoadForm event.  By re-assigning variables XCoord and Y Coord before .Show, any changes made will follow through.

Thanks,
0 Kudos
RobChouinard
Occasional Contributor
Maybe late to the party but here is how I do it. I set a the page's "OnValidate" event to a sub method. I check what I need on that page. If things are not right and I display a message saying so and set ThisEvent.Result = False so the form doesn't close. This way the form doesn't close and have to be reopened.
0 Kudos