Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confirm record change 1

Status
Not open for further replies.

JTimothy

Technical User
Apr 19, 2000
10
US
I want to be able to have a box pop up asking me if I want to change a field (or record) before I save the change. Anyone have a solution?
 
JTimothy,

One way to do this is to trap the DataPostRecord action. You can then prompt the user and then either allow or deny the event, as appropriate for their response.

For example, consider the following code taken from the action event of a record object:

Code:
method action(var eventInfo ActionEvent)
var
   siActionID  smallInt
endVar

   siActionID = eventInfo.id()
   switch
      case siActionID = dataUnlockRecord :

         if not active.action( dataPostRecord ) then
            eventInfo.setErrorCode( userError )
         endIf

      case siActionID = dataPostRecord :

         if self.Touched then
            if msgQuestion( "Confirmation",
               "Are you sure you want to save these " +
               "changes?  They cannot be reversed." ) <> "Yes" then
               eventInfo.setErrorCode( userError )
               active.postAction( dataCancelRecord )
            endIf
         endIf

   endSwitch

endMethod

Now, this adds a bit to the original question, as it also overrides the DataUnlockRecord action to make sure that DataPostRecord is called first.

Calling DataPostRecord before DataUnlockRecord is a good idea, for it handles "flyaway" (record movement as a result of changing a field in the current sort order).

In this example, the user is prompted before changes are made.

You might prefer to confirm the action before the user enters Edit mode. Something like this would be appropriate in that case:

Code:
method action(var eventInfo ActionEvent)

   if eventInfo.id() = dataBeginEdit then
      if msgQuestion( "Confirmation",
         "Are you sure you want to change this record?  " +
         "Saved changes cannot be reversed." ) <> "Yes" then
         eventInfo.setErrorCode( userError )
      endIf
   endIf

endMethod

This approach handles the question before changes are made and may be less annoying to your experienced users.

The scope of your question will depend on where you place the code. As noted earlier, these examples are taken from the record object of a repeating object (a table frame or a multi-record object).

If you wanted to limit this to a single field, you could add something like this to the field's changeValue() event:

Code:
method changeValue(var eventInfo ValueEvent)

   if eventInfo.reason() <> startupValue then
      if msgQuestion( "Confirmation",
         "Are you sure you want to change this field?  " +
         "Saved changes cannot be reversed." ) <> "Yes" then
         eventInfo.setErrorCode( userError )
      endIf
   endIf

endMethod

In this case, we use the reason for the value change to determine whether or not we should request permission to change the field.

As you can see, the central code is pretty straightforward; the trick is determining where to place it and what action to respond to. And the answer to that depends on what you're trying to accomplish.

Hope this helps...

-- Lance
 
Footpad,

I have tried these suggestions with no luck. Any other suggestions? or what am I doing wrong.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top