Subject Re: requery problem (semi reason)
From Charlie <tm@tc.com>
Date Thu, 09 Jan 2020 06:31:56 -0500
Newsgroups dbase.getting-started

I have each query indexed and filtered differently but in sql.  I am going to try to index them in the rowset.  I have a feeling that may be the problem.  I just figured out if I use order by in sql that query is read only in the grid.  That may well have something to do with it.   Well I'll try it later after golf.  

Charlie Wrote:

> Hi Mervyn... Thanks very much.  I had actually tried something very similar by putting the totals code in it's own funcition.  But that never got off the ground as I was trying to call it by function, not class.
>
> At any rate, unfortunately yours does the exact same thing.
>
> I am testing it an easy way by clicking on the erase all button on the form and cancel.  I did this twice two times in testing this and it failed the second time both times.  Here is my code for the erase button:
>
> function PUSHBUTTON3_onClick()
>            local nanswer
>                 nanswer = msgbox( "Are you sure you want to erase sauc values?","Erase?" , 48+4 )
>       if nAnswer == 6 // Yes
>                    form.master9.rowset.first()
>          do while not form.master8.rowset.endofset
>                       form.master9.rowset.fields["sauc"].value = ""
>                            form.master9.rowset.next()
>                    enddo
>                         //do sauccnt.wfm
>                    //form.close()
>                         msgbox( "All Sauc Erased" )
>                 else
>                    msgbox( "Operation Aborted" )
>                 endif
>       return
>
> This is just the easy way to get it to fail.  It will fail with almost anything you do, although some not in just two tries...
>
> I'm wondering if it is possibly my computer??  I doubt it, but I will try it tomorrow on a different computer.
>
> Mervyn Bick Wrote:
>
> > On 09/01/2020 03:36, charlie wrote:
> > > OK I have a theory on what is happening but not sure why.
> > >
> > > If I put code that populates the entryfields with data and the requery in the same function such as form ongot focus, the problem persists with the form freezing and closing with the windows error.
> > >
> > > But if I put the code in the onopen function of the form and leave the requery in the ongotfocus for the form I have no problem.  (Other than the entry fields don't get updated correctly.
> > >
> > > So here are the queries and the code below.  Can anyone give a reason that this is happening so I can fix it?  Thanks much for putting up with this.
> > >
> >
> > I can't tell why but at least I can suggest a way to fix it.
> >
> >
> > Firstly move the code to calculate the count and total for each category
> > from the form's onOpen event handler into it's own function.  Execute
> > the calculate_totals function from the form's onOpen event handler.
> > This takes you back to square 1. :-)
> >
> > In the form's onGotFocus event handler do the requeries and then execute
> > the calculate_totals function.  This takes care of the totals.
> >
> >    function form_onOpen()
> >      set procedure to test.pop additive
> >      form.popupMenu := new testpopup(form,"testPOPUP")
> >      class::calculate_totals()
> >      return
> >
> >    function form_onGotFocus()
> >       form.master1.requery()
> >       form.master2.requery()
> >       form.master3.requery()
> >       form.master4.requery()
> >       form.master5.requery()
> >       form.master6.requery()
> >       form.master7.requery()
> >       form.master8.requery()
> >       form.master9.requery()
> >       form.master9.rowset.first() //shouldn't be necessary but does no harm
> >       class::calculate_totals()
> >       return
> >
> >    function calculate_totals
> >       sel = 0.00
> >       cnt = form.master2.rowset.count()
> >       form.entryfield3.value = cnt
> >       if cnt # 0
> >          do while not form.master2.rowset.endofset
> >             sel = form.master2.rowset.fields["sell"].value +sel
> >             form.master2.rowset.next()
> >          enddo
> >          form.entryfield4.value = sel
> >       else
> >          form.entryfield4.value = 0.00
> >       endif
> >       cnt = 0
> >       sel = 0.00
> >       cnt = form.master3.rowset.count()
> >       form.entryfield9.value = cnt
> >       if cnt # 0
> >          do while not form.master3.rowset.endofset
> >             sel = form.master3.rowset.fields["sell"].value +sel
> >             form.master3.rowset.next()
> >          enddo
> >          form.entryfield10.value = sel
> >       else
> >          form.entryfield10.value = 0.00
> >       endif
> >       cnt = 0
> >       sel = 0.00
> >       cnt = form.master4.rowset.count()
> >       form.entryfield1.value = cnt
> >       if cnt # 0
> >          do while not form.master4.rowset.endofset
> >             sel = form.master4.rowset.fields["sell"].value +sel
> >             form.master4.rowset.next()
> >          enddo
> >          form.entryfield2.value = sel
> >       else
> >          form.entryfield2.value = 0.00
> >       endif
> >       cnt = 0
> >       sel = 0.00
> >       cnt = form.master5.rowset.count()
> >       form.entryfield5.value = cnt
> >       if cnt # 0
> >          do while not form.master5.rowset.endofset
> >             sel = form.master5.rowset.fields["sell"].value +sel
> >             form.master5.rowset.next()
> >          enddo
> >          form.entryfield6.value = sel
> >       else
> >          form.entryfield6.value = 0.00
> >       endif
> >       sel = 0.00
> >       cnt = form.master6.rowset.count()
> >       form.entryfield7.value = cnt
> >       if cnt # 0
> >          do while not form.master6.rowset.endofset
> >            sel = form.master6.rowset.fields["sell"].value +sel
> >            form.master6.rowset.next()
> >          enddo
> >          form.entryfield8.value = sel
> >       else
> >          form.entryfield8.value = 0.00
> >       endif
> >       return
> >
> >
> > Mervyn.
>