Subject Re: Form to Form
From Mervyn Bick <invalid@invalid.invalid>
Date Sat, 13 May 2023 15:32:04 +0200
Newsgroups dbase.getting-started

On 2023/05/13 11:49, Mervyn Bick wrote:

> Instead of using the entryfield's onLostFocus event handler use its
> onKey event handler.
> Time's up for now.  Keep tuned in for the next exciting episode. :-)

Make hay while the sun shines. Code while the power is on. :-)

Using the entryfield's onKey event handler instead of the onLostFocus
event handler gives several advantages as each character can be examined
as it is typed in.

If the first character is a digit set the cPat_no index for the query.
This will display the table in the grid with the matching record
selected.  As each subsequent digit is entered the rowpointer will move
to the correct record.

If the first character is not a digit set fullname as the index for the

As subsequent digits or characters are typed in the rowpointer moves.

As each keystroke is monitored it is possible to test for Enter (nChar =
13) and Tab (nChar = 9) and simulate a mouse click on the GOTO button.

   function ENTRYFIELD1_onKey(nChar, nPosition,bShift,bControl)
       local cVal
       //If Enter or Tab press, execute the function pb_goto_onClick
       if nChar = 13 or nChar = 9
       //Check first character and set appropriate index
       if nPosition = 2 and not isAlpha(this.value)
          form.patients1.rowset.indexname = 'cID'
       if nPosition = 2 and isAlpha(this.value)
          form.patients1.rowset.indexname = 'fullname'
       //Change rowpointer
       //findKey() requires a variable, not an object property,
       //as its argument hence the use of cVal instead of this.value
       if isAlpha(this.value)
         cVal = lower(trim(this.value))
         cVal =right(space(5)+trim(this.value),5)

   function PBGOTO_OnClick()
     //The pat_no value has been saved to a user-defined property
     //of editpastest   form.edit_pat_test.goto   in memory
     //Set the rowset pointer in editpattest
     //I assume the query name in editpattest is also patient1. If not,
     //use the correct query name.
     //If you want the form opened with readmodal(), comment out the
     //next line and uncomment the two lines after it.
//    form.edit_pat_test.mdi = false
//    form.edit_pat_test.readmodal()

Just as the entryfield's onKey event handler can make life simpler for
the user by using the Enter or Tab key to open the child form, one can
use the grid's onLeftMouseUp event handler to open the child form when
the user clicks on an entry in the grid.

   function GRID1_onLeftMouseDown(flags, col, row)