Subject Re: Form to Form
From Mervyn Bick <invalid@invalid.invalid>
Date Fri, 12 May 2023 12:54:37 +0200
Newsgroups dbase.getting-started

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

>    function PBGOTO_OnClick()
>      //Save the pat_no value to a user-defined property of editpastest
>      //in memory
>      form.edit_pat_test.Goto = class::get_pat_no() //Discussed later.
>      if form.edit_pat_test.goto <> null
>        //Set the rowset pointer in editpastest
>        //I assume the query name in editpattest is also patient1. If not,
>        //use the correct query name.
>        form.edit_pat_test.patient1.rowset.goto(form.edit_pat_test.goto)
>        form.edit_pat_test.open()
>      else
>        msgbox('Invalid patient number or name')
>      endif
>      return
>
>
>    function get_pat_no()
>      //As the user can enter either the patient number or the patient
>      //name you need some mechanism for making sure the user enters a
>      //valid value.
>      local nRet
>      nRet = null // If a record is found this will be overwritten
>
>      // Code needed here to verify selection.
>
>      return nRet

After a bit more thought, getting the pat_no required is better done
before the user clicks on the GOTO pushbuton.


   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.
     form.edit_pat_test.patient1.rowset.goto(form.edit_pat_test.goto)
     form.edit_pat_test.open()
     return

As the user moves through the patient file use the rowset's onNavigate
event handler to save the pat_no to form.edit_pat_test.goto  ready for
the user to click the GOTO button.  The user can use the up and down
arrow keys to move through the patient table displayed in a grid in
which case a new pat_no will be saved each time a new record is
selected.  If the user uses the mouse wheel to scroll the grid it will
be necessary to click on a record to save the pat_no.

     function rowset_onNavigate(type, nRows)
       local cPatient,f
       form.edit_pat_test.goto = this.fields['pat_no'].value
       //Display the selected patient's name in a separate entryfield
       //Don't overwrite the entryfield used for keyboard selection
       f = form.patient1.rowset.fields //To save typing later
       cPatient = f['pat_no'].value + ' --- '
       cPatient += trim(f['lname'].value) + ', '
       cpatient += trim(f['fname'].value)
       form.entryfield2.value = cPatient
       return

To make sure form.edit_pat_test.goto has the value of the first patent
when the form opens use the query's onOpen event handler.  If you don't
do this clicking the GOTO button to open the edit form for the first
patient will give an error.

     function PATIENT1_onOpen()
       form.edit_pat_test.goto = this.rowset.fields['pat_no'].value
       return

You are going to have to decide whether you want to open the the main
form with the patients displayed in patient order or name order.
Probably the name order would be the better choice.

To allow the user to type either a pat_no or a last name into
entryfield1 may mean some fancy footwork in entryfield1's onKey event
handler.  Is your pat_no field numeric(5,0) or is it char(5)?

We're heading into another 4hour power outage shortly so that's it for now.

Mervyn.