f



How to reference a subform?

I have a main form called ProspectForm, and then a subform called RefViewBa=
sic. On the RefViewBasic header I have a text field and a search button whi=
ch opens a separate pop up form called RefSearch. Once results show on RefS=
earch, a command button next to each result should then populate RefViewBas=
ic with that record. Here is my code which instead opens a new version of R=
efViewBasic on it's own instead of populating the subform. How do I refer t=
o the subform in this code to get my desired result?

Private Sub cmdGoRefView_Click()
On Error GoTo Err_cmdGoRefView_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName =3D "RefViewBasic"
   =20
    stLinkCriteria =3D "[RefID]=3D" & "'" & Me![RefID] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdGoRefView_Click:
    Exit Sub

Err_cmdGoRefView_Click:
    MsgBox Err.Description
    Resume Exit_cmdGoRefView_Click
End Sub

Thanks in advance for your help,
magmike
0
magmike
12/20/2016 3:34:06 AM
comp.databases.ms-access 42670 articles. 0 followers. Post Follow

3 Replies
405 Views

Similar Articles

[PageSpeed] 18

Hi magmike,

Am 20.12.2016 um 04:34 schrieb magmike:
> I have a main form called ProspectForm, and then a subform called RefViewBasic. On the RefViewBasic header I have a text field and a search button which opens a separate pop up form called RefSearch. Once results show on RefSearch, a command button next to each result should then populate RefViewBasic with that record. Here is my code which instead opens a new version of RefViewBasic on it's own instead of populating the subform. How do I refer to the subform in this code to get my desired result?
>
> Private Sub cmdGoRefView_Click()
> On Error GoTo Err_cmdGoRefView_Click
>
>      Dim stDocName As String
>      Dim stLinkCriteria As String
>
>      stDocName = "RefViewBasic"
>      
>      stLinkCriteria = "[RefID]=" & "'" & Me![RefID] & "'"
>      DoCmd.OpenForm stDocName, , , stLinkCriteria
>
> Exit_cmdGoRefView_Click:
>      Exit Sub
>
> Err_cmdGoRefView_Click:
>      MsgBox Err.Description
>      Resu
i needed a similar design in my software and my solution was to open the 
searchform from the subform (RefViewBasic) as a modal dialog form. In 
the formfooter of the searchform there is one 'ok' button with hides the 
searchform. The execution control is then switch back to subform and i 
am able to get all needed informations from the searchform, e.x. current 
primary key and so on. No need to populate a button for each record. 
After that i close the hidden form and assign a new recordsource based 
on this infos. This control flow is much easier to handle than to 
manipulate the subfrom from the popup searchform. Btw. with this design 
you will be also be able to handle the close button from the dialog form.

Ulrich



0
UTF
12/20/2016 1:01:01 AM
> 
> Private Sub cmdGoRefView_Click()
> On Error GoTo Err_cmdGoRefView_Click
> 
>     Dim stDocName As String
>     Dim stLinkCriteria As String
> 
>     stDocName = "RefViewBasic"
>     
>     stLinkCriteria = "[RefID]=" & "'" & Me![RefID] & "'"

' assuming the sub-form control name is RefViewBasic 
' You can set a filter on the sub-form
me.RefViewBasic.form.filter = stLinkCriteria
me.RefViewBasic.form.filteron = true
me.RefViewBasic.form.requery

' Otherwise set link master field of the sub-form to me![RefID] 
' and the link child field to [RefID], then re-query the subform. 


> 
> Exit_cmdGoRefView_Click:
>     Exit Sub
> 
> Err_cmdGoRefView_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdGoRefView_Click
> End Sub
> 
> Thanks in advance for your help,
> magmike

0
Ron
12/20/2016 1:09:36 PM
See (and save) this:
 http://access.mvps.org/access/forms/frm0031.htm


magmike wrote:

> I have a main form called ProspectForm, and then a subform called
> RefViewBasic. On the RefViewBasic header I have a text field and a
> search button which opens a separate pop up form called RefSearch.
> Once results show on RefSearch, a command button next to each result
> should then populate RefViewBasic with that record. Here is my code
> which instead opens a new version of RefViewBasic on it's own instead
> of populating the subform. How do I refer to the subform in this code
> to get my desired result?
> 
> Private Sub cmdGoRefView_Click()
> On Error GoTo Err_cmdGoRefView_Click
> 
>     Dim stDocName As String
>     Dim stLinkCriteria As String
> 
>     stDocName = "RefViewBasic"
>     
>     stLinkCriteria = "[RefID]=" & "'" & Me![RefID] & "'"
>     DoCmd.OpenForm stDocName, , , stLinkCriteria
> 
> Exit_cmdGoRefView_Click:
>     Exit Sub
> 
> Err_cmdGoRefView_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdGoRefView_Click
> End Sub
> 
> Thanks in advance for your help,
> magmike

0
Joan
12/20/2016 1:44:32 PM
Reply: