Select to view content in your preferred language

Returning to last page visited on reopening form

823
4
02-10-2011 12:04 PM
JaneOnorati
Regular Contributor
I have an editform with 7 pages.  I made it so the user can close the form and save the record, and then reopen it later in the same session to continue editing the same record.  All of it works fine, but the customer wants to have the form open at the same page they left off at. 

I got this to work except for one situation - if the user closes the form using the OK button they are presented with a prompt asking if they really want to close or not (this is handled using the OnValidate event for each page).  If they choose not to close, they are always returned to the first page.  This appears to be by design and there is no event I can use to control this behavior.  I'm stumped - any ideas out there?
Tags (3)
0 Kudos
4 Replies
RolfBroch
Frequent Contributor
You can add code in the onsetactive script for each page and save the form and page information everytime you activate a new page.

Rolf
0 Kudos
JaneOnorati
Regular Contributor
Rolf,

I am using that method, but it does not matter that I have stored the last page index.  The code I have that activates the last page (to display it on reopening the form) is run for the OnLoad event of the form.  When you click on the OK button and then back out - it puts you back at the first page because this is the default behavior, and the OnLoad form event is not fired in this case.  I'm thinking I need to handle the OnValidate for the pages differently or use an OnOK event to address this, but how?

-Jane
0 Kudos
RolfBroch
Frequent Contributor
When you open up a form the onsetactive event for page 1 fires BEFORE the onload event of the form, go figure. Below is the sequence of events.

When you first open a form with 3 pages:
Applet_OnLoad
Form OnSetActive
Page1 OnLoad
Page1 OnSetActive
Page2 OnLoad
Page3 OnLoad
Form OnLoad

Use the enclosed applet to test what happens when you change pages, click ok or cancel. The sequence of events will be written to a file called debug.txt which resides in the ArcPad\System folder.
0 Kudos
JaneOnorati
Regular Contributor
Rolf,

Thanks for the event logging applet.  I have never found any documentation on the order of events in ArcPad which was part of the problem.  The other part of the problem was that I had copied some code for the OnValidate event without really understanding how it worked.  I had the OnValidate event sub only called for the first page of the form.  Now I understand that this is why it always returned me to that page instead of the last page that was active. 

To get this to work the way I wanted, I added the event to each page but made it so nothing happens unless the OnValidate event is for the same page as the one that has been stored as the last active page:

Sub Page_OnValidate()  ' Page OK button click event handler
  Dim objPage
  Set objPage = ThisEvent.Object
  If objPage.Index = Application.UserProperties ("lastActivePg") Then
    ThisEvent.Result = False
    ThisEvent.MessageText  = "Close form and save changes?" + vbCr + vbCr + _
    "  - Click YES to close form and save changes." + vbCr + vbCr + _
    "  - Click NO to return to form."
    ThisEvent.MessageType = apYesNo + apExclamation   'YES/NO and Exclamation icon
  End If
End Sub

-Jane
0 Kudos