Select to view content in your preferred language

Cancel close form

973
1
11-10-2010 11:26 AM
rasmusborgstrøm
Emerging Contributor
hi

I am trying to write a script for an editform in ArcPad, that should make it possible to Cancel the closing of the form if the cancel button is clicked, e.g. by a msgbox "Are you sure you need to close the form?".
I have tried to put this code into the onunload event of the form, but with no luck;
If MsgBox("Close?", vbYesNo) = vbYes Then
     Exit Sub
  Else
    Cancel = True
  End If

When the user clicks No, the form still closes!

Can anybody help here?
Cheers,
Rasmus
Tags (3)
0 Kudos
1 Reply
EricHajek1
Regular Contributor
Hi Rasmus,

I found something similar to this code on the forums or a developer's sample or somewhere a while ago, and have been using it ever since.

Call this sub from the "onQueryCancel" event of each page.
Sub OnFormCancel 
 Dim bResult
 bResult = Application.MessageBox ("Are you sure you want to cancel?", apYesNo, "Cancel?")
 If bResult = apNo Then
  ThisEvent.Result = False
 End If
 If bResult = apYes Then
  ThisEvent.Result = True
 End If
End Sub


Eric
0 Kudos