Subject |
Re: Form to Form |
From |
Peter <phb2020@hotmail.com> |
Date |
Thu, 01 Jun 2023 13:49:17 -0400 |
Newsgroups |
dbase.getting-started |
Mervyn Bick Wrote:
> 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
> query.
>
> 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
> form.pb_goto_onClick()
> endif
> //Check first character and set appropriate index
> if nPosition = 2 and not isAlpha(this.value)
> form.patients1.rowset.indexname = 'cID'
> endif
> if nPosition = 2 and isAlpha(this.value)
> form.patients1.rowset.indexname = 'fullname'
> endif
> //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))
> form.patients1.rowset.findkey(cVal)
> else
> cVal =right(space(5)+trim(this.value),5)
> form.patients1.rowset.findkey(cVal)
> endif
> return
>
>
> 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)
> //If you want the form opened with readmodal(), comment out the
> //next line and uncomment the two lines after it.
> form.edit_pat_test.open()
> // form.edit_pat_test.mdi = false
> // form.edit_pat_test.readmodal()
> return
>
> 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)
> form.pb_goto_onClick()
> return
>
> Mervyn.
Hi Mervyn,
I'm back at work, but still no success at getting form1 to get form2 to get the custom "variable" to change the query1 in form 2.
I am showing the adjustments as per your latest messages.
To answer some of your questions, pat_no is a numeric field of 5 digits. The grid allows the user to enter either a number (the Pat_no, unique number to each patient, index set to pat_no) or a character (index set to lname+fname). No apparent need to check for going past last rowset or above first rowset as grid does that.
I know you have suggested several changes with OnKey, etc, but I need to get this error corrected first.
I thought that there might be a problem with "form.editpattest.goto" if "goto" is reserved wording. So I changed form.editpattest.goto to form.editpattest.goedit. But I still get same errors. For instance in editpattest.wfm shown below, the error is editpattest variable undefined.
In PATIENT1.onOpen (the query name for gridtest form), you suggested setting the rowset before PBGOEDIT_onClick is clicked, hence putting that in onOpen. That seems to be OK. BUT, second line in PBGOEDIT_onClick does not change the rowset. (See form.editpattest.query1.rowset.GOTO(form.editpattest.goedit))
I tried a requery() but that didn't work either.
I look forward to suggestions and expertise from you and your fellow programmers.
Peter
This onOpen() is in editpattest.wfm
function form_onOpen()
form.query1.rowset.FINDKEY(form.editpattest.goedit)
return
These other methods are in Gridtest.wfm
function PATIENT1_onOpen //the query.
set procedure to editpattest.wfm
form.editpattest = new editpattestForm()
form.editpattest.goedit = this.rowset.fields["pat_no"].value
return
function PBGOEDIT_onClick
//query1 is in editpattest.wrm
form.editpattest.query1.rowset.GOTO(form.editpattest.goedit)
form.editpattest.mdi = false
form.editpattest.readmodal()
return
function PBQUIT_onClick()
local f
f = findinstance("editpattestForm")
do while not empty(f)
f.close()
f = findinstance("editpattestForm",f)
enddo
form.editpattest = null
close databases
form.close()
return
|
|