Subject Re: Referencing a subform
From Ken Mayer <dbase@nospam.goldenstag.net>
Date Thu, 30 Nov 2023 10:28:22 -0800
Newsgroups dbase.getting-started

On 11/30/2023 8:27 AM, Tim Ward wrote:
> Hi,
> I have a subform on a form opened by a pushbutton like below and works
> OK for what I need.
>
> function PB_Subform_onClick()
>      f = this.parent.form
>      set procedure to DeliveryList.wfm additive
>         x = new DeliveryListForm( f, "Mypopup" )
>      x.top    := 10
>         x.left    := 20
>      x.open()
>        return
>
> In the main form I have some custom pushbuttons and when I click one of
> these I want to action different things on the subform, like refreshing
> the grid there or changing a text field.
>
> What's the correct syntax as I can't seem to get it right. So below is a
> line setting the value stored as a custom property of the pushbutton
> (Order_number) to the rowset on the main form, so I can reference the
> main form OK
>
>
> function MyMapButton_ONLEFTDBLCLICK
>      this.parent.DropPlanner1.rowset.fields["orderNumber"].value =
> this.Order_number
>
> But how do I refresh the grid on the subform when I click a custom
> pushbutton on the main form.
>

You're running into an issue of scope. The subform is defined in the one
method, the main form doesn't know anything about it.

You can create a reference to the subform on the mainform:

function PB_Subform_onClick()
     f = this.parent.form
     set procedure to DeliveryList.wfm additive
        x = new DeliveryListForm( f, "Mypopup" )
     x.top    := 10
        x.left    := 20
     x.open()
// create a custom property of the main form so you can
// reference the subform
f.MySubForm = x

       return

In other code on the main form, you can then click a button, and in the
button's code:

f.MySubForm.rowset.refreshControls()

and so on.

Ken


--
*Ken Mayer*
Ken's dBASE Page: http://www.goldenstag.net/dbase
The dUFLP: http://www.goldenstag.net/dbase/index.htm#duflp
dBASE Books: http://www.goldenstag.net/dbase/Books/dBASEBooks.htm
dBASE Tutorial: http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm
dBASE Web Tutorial: http://www.goldenstag.net/dbase/WebTutorial/00_Menu.htm
dBASE DOS to Windows Tutorial:
http://www.goldenstag.net/dbase/DtoWTutorial/00_Menu.htm