Subject |
Re: Form to Form |
From |
Peter <phb2020@hotmail.com> |
Date |
Fri, 09 Jun 2023 14:23:27 -0400 |
Newsgroups |
dbase.getting-started |
Peter wrote:
Thank you for these wfm's. I was not able to create the tablename as you wrote. Rather than debugging, I copied and pasted into my wfm, changing names as needed, at least until there were no errors that popped up.
The problem is that, for some reason, the findkey() does not move the rowset to the selected pat_no in the editpattest.wfm, that was instantiated earlier.
I am copying the PBGOEDIT_onClick with some msgbox() results.
I hope you can help solve this problem.
With thanks,
Peter
function PBGOEDIT_onClick
private cpat_no,clname
store "" to cpat_no,clname
//patient1 is name of main program query
cpat_no = form.patient1.rowset.fields["pat_no"].value
msgbox("cpat_no: "+cpat_no) //this shows CORRECT pat_no
//query1 is name of editpattest program query
form.editpattest.query1.rowset.findkey(cpat_no)
form.editpattest.query1.requery() //this made no difference
clname = form.editpattest.query1.rowset.fields["lname"].value
msgbox("clname: "+clname) // this shows Last Name of rowset.first()
//there is no change in rowset in "findkey(cpat_no)" above
form.editpattest.mdi = false
form.editpattest.readmodal()
return
Mervyn Bick Wrote:
> On 2023/06/01 19:49, Peter wrote:
>
> > 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.
> >
>
> There's more than one way to do what you want. The two example forms
> attached are merely one possibility.
>
> The main form opens with focus on the blank entryfield. The first
> character entered determines which index to set. Each keystroke refines
> the selection. If the rowpointer is against the correct record in the
> grid TAB or ENTER executes the function pushbutton1_onClick().
>
> Instead of typing the full name the user can use the mouse to select the
> correct record and then click on the pushbutton. Try compu which are
> the first characters of three records.
>
> The function pushbutton1_onClick() saves the customerId for the selected
> record and then uses that to navigate to the same record in the instance
> of edit_form held in memory. The edit form is then launched using
> readModal(). To ensure that the user can't close the edit form without
> either saving or abandoning any changed the form's sysMenu property is
> set false.
>
> Although the mouse can be used on the edit form I prefer not to use it.
> The user can, therefore, enter edit mode by pressing Enter when the form
> opens. All further editing, including saving and closing the form, can
> be done from the keyboard.
>
> Mervyn.
>
>
>
>
>
>
>
>
>
>
> d = new database()
> d.databaseName = "dbasesamples"
> d.active = true
> tDef = new tableDef()
> tDef.database := d
> tDef.tableName := "customers"
> tDef.load()
> for n = 1 to tdef.indexes.size
> // cIndex = tDef.indexes[n].indexname
> // ?cindex
> if upper(tDef.indexes[n].indexname) = 'COMPANY_LOWER'
> cSafety = set('safety')
> set safety off
> use :dbasesamples:customers exclusive
> index on lower(company) tag company_lower
> use
> set safety &cSafety
> n = tdef.indexes.size //Abort loop
> endif
> next
> d.active = false
>
>
> ** END HEADER -- do not remove this line
> //
> // Generated on 2023-06-02
> //
> parameter bModal
> local f
> f = new Main_formForm()
> if (bModal)
> f.mdi = false // ensure not MDI
> f.readModal()
> else
> f.open()
> endif
>
> class Main_formForm of FORM
> with (this)
> canClose = class::FORM_ONCLOSE
> onOpen = class::FORM_ONOPEN
> height = 20.0
> left = 2.0
> top = 0.0
> width = 100.0
> text = ""
> endwith
>
> this.DBASESAMPLES1 = new DATABASE(this)
> with (this.DBASESAMPLES1)
> left = 13.0
> width = 11.0
> height = 1.0
> databaseName = "DBASESAMPLES"
> active = true
> endwith
>
> this.CUSTOMERS1 = new QUERY(this)
> with (this.CUSTOMERS1)
> left = 6.0
> width = 9.0
> height = 1.0
> database = form.dbasesamples1
> sql = "select * from CUSTOMERS.DBF"
> active = true
> endwith
>
> this.GRID1 = new GRID(this)
> with (this.GRID1)
> dataLink = form.customers1.rowset
> height = 9.5455
> left = 7.7143
> top = 2.1364
> width = 82.5714
> endwith
>
> this.ENTRYFIELD1 = new ENTRYFIELD(this)
> with (this.ENTRYFIELD1)
> onKey = class::ENTRYFIELD1_ONKEY
> height = 1.0
> left = 27.2857
> top = 17.7273
> width = 19.4286
> value = ""
> endwith
>
> this.TEXT1 = new TEXT(this)
> with (this.TEXT1)
> height = 4.4545
> left = 23.7143
> top = 12.0909
> width = 36.0
> text = "Enter Customer ID (max 101) or <P>Company name. (Not case-sensitive). <P>Left-click pushbutton or press either Enter or Tab to open Edit form for the selected record."
> endwith
>
> this.PUSHBUTTON1 = new PUSHBUTTON(this)
> with (this.PUSHBUTTON1)
> onClick = class::PUSHBUTTON1_ONCLICK
> height = 1.7273
> left = 60.1429
> top = 17.3182
> width = 15.2857
> text = "Edit selected record"
> endwith
>
> this.rowset = this.customers1.rowset
>
> function ENTRYFIELD1_onKey(nChar, nPosition,bShift,bControl)
> local cVal
> if len(this.value) <> 0 //Avoid error if entryfield is cleared
> //If Enter or Tab press, execute the function pb_goto_onClick
> if nChar = 13 or nChar = 9
> form.pushbutton1_onClick()
> endif
> //Check first character and set appropriate index
> if nPosition = 2 and not isAlpha(this.value)
> form.CUSTOMERS1.rowset.indexname = 'CustomerID'
> endif
> if nPosition = 2 and isAlpha(this.value)
> form.CUSTOMERS1.rowset.indexname = 'company_lower'
> 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 = trim(this.value)
> form.CUSTOMERS1.rowset.findkey(cVal)
> else
> cVal = val(this.value)
> form.CUSTOMERS1.rowset.findkey(cVal)
> endif
> endif
> return
>
> function PUSHBUTTON1_onClick()
> form.edit_form = new edit_formForm() //Create instance of edit_form in memory.
> form.edit_form.parent = form // Open path back to form from edit_form to facilitate requery().
> nCustID = form.customers1.rowset.fields['customerID'].value //Save the customerID value
> form.edit_form.customers1.rowset.findkey(nCustId) //Move the rowpointer to the correct record in the edit form
> form.edit_form.mdi = false
> form.edit_form.readModal()
> return
>
> function form_onClose()
> form.customers1.active = false
> form.dbasesamples1.active = false
> return true
>
> function form_onOpen()
> set procedure to edit_form.wfm
> form.entryfield1.setFocus()
> return
>
> endclass
>
> ** END HEADER -- do not remove this line
> //
> // Generated on 2023-06-02
> //
> parameter bModal
> local f
> f = new edit_formForm()
> if (bModal)
> f.mdi = false // ensure not MDI
> f.readModal()
> else
> f.open()
> endif
>
> class edit_formForm of FORM
> with (this)
> onOpen = class::FORM_ONOPEN
> onClose = class::FORM_ONCLOSE
> height = 20.0
> left = 30.1429
> top = 4.2727
> width = 100.0
> text = ""
> mdi = false
> sysMenu = false
> endwith
>
> this.DBASESAMPLES1 = new DATABASE(this)
> with (this.DBASESAMPLES1)
> left = 9.0
> width = 11.0
> height = 1.0
> databaseName = "DBASESAMPLES"
> active = true
> endwith
>
> this.CUSTOMERS1 = new QUERY(this)
> with (this.CUSTOMERS1)
> width = 9.0
> height = 1.0
> database = form.dbasesamples1
> sql = "select * from CUSTOMERS.DBF"
> active = true
> endwith
>
> with (this.CUSTOMERS1.rowset)
> indexName = "CUSTOMERID"
> endwith
>
> this.ENTRYFIELDCOMPANY1 = new ENTRYFIELD(this)
> with (this.ENTRYFIELDCOMPANY1)
> dataLink = form.customers1.rowset.fields["company"]
> height = 1.0
> left = 11.1429
> top = 5.8182
> width = 42.0
> endwith
>
> this.ENTRYFIELDADDRESS11 = new ENTRYFIELD(this)
> with (this.ENTRYFIELDADDRESS11)
> dataLink = form.customers1.rowset.fields["address1"]
> height = 1.0
> left = 11.1429
> top = 8.0455
> width = 32.0
> endwith
>
> this.ENTRYFIELDADDRESS21 = new ENTRYFIELD(this)
> with (this.ENTRYFIELDADDRESS21)
> dataLink = form.customers1.rowset.fields["address2"]
> height = 1.0
> left = 11.1429
> top = 10.3182
> width = 32.0
> endwith
>
> this.ENTRYFIELDCITY1 = new ENTRYFIELD(this)
> with (this.ENTRYFIELDCITY1)
> dataLink = form.customers1.rowset.fields["city"]
> height = 1.0
> left = 11.1429
> top = 12.5455
> width = 22.0
> endwith
>
> this.ENTRYFIELDSTATE1 = new ENTRYFIELD(this)
> with (this.ENTRYFIELDSTATE1)
> dataLink = form.customers1.rowset.fields["state"]
> height = 1.0
> left = 11.1429
> top = 14.6364
> width = 4.0
> endwith
>
> this.ENTRYFIELDZIP1 = new ENTRYFIELD(this)
> with (this.ENTRYFIELDZIP1)
> dataLink = form.customers1.rowset.fields["zip"]
> height = 1.0
> left = 22.8571
> top = 14.5
> width = 12.0
> endwith
>
> this.ENTRYFIELDFIRSTNAME1 = new ENTRYFIELD(this)
> with (this.ENTRYFIELDFIRSTNAME1)
> dataLink = form.customers1.rowset.fields["firstname"]
> height = 1.0
> left = 56.1429
> top = 7.7273
> width = 17.0
> endwith
>
> this.ENTRYFIELDLASTNAME1 = new ENTRYFIELD(this)
> with (this.ENTRYFIELDLASTNAME1)
> dataLink = form.customers1.rowset.fields["lastname"]
> height = 1.0
> left = 75.1429
> top = 7.8182
> width = 17.0
> endwith
>
> this.ENTRYFIELDPHONE1 = new ENTRYFIELD(this)
> with (this.ENTRYFIELDPHONE1)
> dataLink = form.customers1.rowset.fields["phone"]
> height = 1.0
> left = 62.8571
> top = 10.2727
> width = 22.0
> endwith
>
> this.PUSHBUTTON1 = new PUSHBUTTON(this)
> with (this.PUSHBUTTON1)
> onClick = class::PUSHBUTTON1_ONCLICK
> height = 1.0909
> left = 12.8571
> top = 17.9545
> width = 15.2857
> text = "Edit"
> endwith
>
> this.PUSHBUTTON2 = new PUSHBUTTON(this)
> with (this.PUSHBUTTON2)
> onClick = class::PUSHBUTTON2_ONCLICK
> height = 1.0909
> left = 33.7143
> top = 17.9545
> width = 15.2857
> text = "Save"
> endwith
>
> this.PUSHBUTTON3 = new PUSHBUTTON(this)
> with (this.PUSHBUTTON3)
> onClick = class::PUSHBUTTON3_ONCLICK
> height = 1.0909
> left = 54.5714
> top = 17.9545
> width = 15.2857
> text = "Abandon"
> endwith
>
> this.PUSHBUTTON4 = new PUSHBUTTON(this)
> with (this.PUSHBUTTON4)
> onClick = class::PUSHBUTTON4_ONCLICK
> height = 1.0909
> left = 75.4286
> top = 17.9545
> width = 15.2857
> text = "Close form"
> endwith
>
> this.TEXT1 = new TEXT(this)
> with (this.TEXT1)
> height = 4.4545
> left = 24.1429
> top = 0.4545
> width = 50.7143
> text = "<p>The Edit button has focus when the form opens. Either press Enter or click on the button to enable edit. <P></p><p>Tab moves through entryfields.</p><p></p><p> Any changes must either be saved or abandoned before the form can be closed.</p>"
> endwith
>
> this.rowset = this.customers1.rowset
>
> function PUSHBUTTON1_onClick()
> form.entryfieldcompany1.setFocus() // First field. User can now Tab to following fields
> form.customers1.rowset.beginEdit()
> return
>
> function PUSHBUTTON2_onClick()
> form.customers1.rowset.save()
> form.parent.customers1.requery()
> return
>
> function PUSHBUTTON3_onClick()
> form.customers1.rowset.abandon()
> return
>
> function PUSHBUTTON4_onClick()
> if form.customers1.rowset.modified = true
> msgbox('Data modified. Abandon or Save the changes'+chr(13)+chr(10)+ 'before the form can be closed') = 1
> else
> form.close()
> endif
> return
>
> function form_onClose()
> form.customers1.active = false
> form.dbasesamples1.active = false
> return
>
> function form_onOpen()
> form.pushbutton1.setFocus() //When form opens pressing Enter will initiate edit mode.
> return
>
> endclass
>
|
|