How to Prevent Screen Dropping Out with Disabled Button

ID: Q125748

The information in this article applies to:

SUMMARY

If the screen you are running suddenly stops running after you click an object like a button, you may have code running that is disabling the object you have just clicked.

For example, when you leave a GET field either by pressing the TAB or ENTER key or by clicking with the mouse, the VALID clause of that object is evaluated. If the VALID code snippit disables the next object that gets the focus, the screen will stop running. The reason you are dropping out of your screen is because the object that receives the focus has been disabled, and then receives the focus anyway.

A common situation for this dilemma is where you want to allow your users to click a "Next" button to move to the next record in the table, however, if the information has been modified in one of the input objects on the screen, you want to force the user to choose to save or cancel those changes by clicking different buttons.

The solution is to move the focus to an object that has not been disabled. In this case, move the focus to the Save button, diverting the focus from the Next button, even after clicking the Next button.

MORE INFORMATION

The example steps below demonstrate a simple solution. This example uses the names "m.fieldname" for an input object, "next" and "save" for push buttons and a variable called "old_fieldname" to store the previous value of the input object. It also loads the library Foxtools, for use of the MSGBOX() function.

1. Create a screen with three objects on it. Write code for the WHEN and

    VALID code snippets, substituting your table, field and variable names
    as wanted.

2. Put the following code in the Setup code snippit:

   m.fieldname = table.fieldname
   old_fieldname = m.fieldname
   SET LIBRARY TO C:\fpw26a\foxtools.fll

3. Add an input or GET object (called m.fieldname) with the following code
   snippets:

   * get when clause
   old_fieldname = m.fieldname
   SHOW OBJECT OBJNUM(save) DISABLED

   * get valid clause
   IF m.fieldname <> old_fieldname
      SHOW OBJECT OBJNUM(save) ENABLED
   ENDIF

4. Add a "Next" button (called next) that will move the record pointer to
   the next record when clicked.

   * next when clause
   IF m.fieldname <> old_fieldname
      =MsgBox("You must Save","ALERT",0)
      SHOW OBJECT OBJNUM(save) ENABLED
      SHOW OBJECT OBJNUM(next) DISABLED
      _CUROBJ=OBJNUM(save)
   ENDIF

   * next valid clause
   SKIP
   m.fieldname = table.fieldname
   old_fieldname = m.fieldname
   SHOW OBJECT OBJNUM(save) DISABLED
   SHOW GETS

5. Add a "Save" button (called save) that will write the GET field to the
   table only if the content of the GET object has changed, when the Save
   button is clicked.

   * save when clause
   SHOW OBJECT OBJNUM(next) DISABLED

   * valid clause
   SHOW OBJECT OBJNUM(next) ENABLED
   SHOW OBJECT OBJNUM(save) DISABLED
   REPLACE tablename.fieldname WITH m.fieldname
   old_fieldname = m.fieldname

Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 2.60a KBCategory: kbprg kbcode KBSubcategory: FxprgGeneral

Last Reviewed: June 27, 1995