Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can a subform reference the correct instance of parent form?

Status
Not open for further replies.

MontyBurns

Programmer
Oct 3, 2001
99
GB
Hi,

I have a subform (frmSubFiles) with some code which does a recordcount and updates a txtbox on the parent form (frmIFLR).

Private Sub Form_Current()
Dim intIFLRid As Long

If Not IsNull(Forms!frmIFLR.IFLRid) Then
intIFLRid = Forms!frmIFLR.IFLRid
Else:
intIFLRid = 0
End If

Forms!frmIFLR.txtNumOfFiles = DCount("*", _
"tblIFLRtoClient", "IFLRid = " & intIFLRid)

End Sub

This works fine initially, but when I click on a command button on the parent form to open a new instance of itself, the code gets confused.

It doesn't seem to know which instance it should look at. I could use the Public variable which is holding the reference to the new instance of the form to refer to the main form, but then what about the initial instance of the form?

What can I do?

Thanks,
Burns
 
I think a form has a parent property. I'm not exactly sure, but I think
Code:
Me.Parent.Name
should return the name of the parent form, for example.

Best regards
 
Me.Parent.Name will return the name of the parent not the instance
I would try some thing like this in my app when I add a new instance of a form it has a separate caption select some unique to the parent and I add a text box called fn to the subform
For co = 0 To 20
If Forms(co).uniqueitem = Me.uniqueitem Then
Forms!subforname!fn = co
Exit For
End If
Next co
and reference it like forms(me!fn).textboxname
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top