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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can subform know its name in parent form

Status
Not open for further replies.

PeDa

Technical User
Oct 10, 2002
227
NL
My form "Mainform" contains a number of identical subforms "MySubform" (i.e. they all have the same Source Object). In Mainform their names are Subform1, Subform2, Subform3... How can I, in the code of the subform, determine in which instance of the subform I am working? Me.Name returns "MySubform", and not "Subform1" or whatever.

 
Not even going to inquire as to why you would need multiple, identical Subforms on a single Main Form! But presumably each iteration of the Subform has a different Caption, i.e. Subform1, Subform2, etc. to identify it to the user. From any given Subform you should be able to use Me.Caption to to identify the exact one currently being used. If you simply Copied & Pasted one Subform several times, you may need to go in and modify each one's Caption Property.

Linq ;0)>

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Thank you, MissingLinq, but perhaps I didn't explain clearly enough. There is only one actual subform, which I include five times in my main form (and don't worry, there is a good reason), so all five instances have the same Caption. However, upon further reflection, the solution is quite simple: put an invisible textbox on the subform, and load this with a different value in each instance at load time.
 
Sounds like a plan, Stan!

Good luck with your project!



The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Code:
Public Function getSubFormControl(subfrm As Access.Form) As Access.SubForm
  Dim ctrl As Access.Control
  For Each ctrl In subfrm.Parent.Controls
    'Find if it is a subform control
    If TypeOf ctrl Is Access.SubForm Then
      'See if the form in the subform control is the active subform
      If ctrl.Form Is subfrm Then
        Set getSubFormControl = ctrl
      End If
    End If
  Next ctrl
End Function

how to call from a subform instance
Code:
Private Sub fldOne_DblClick(Cancel As Integer)
  MsgBox getSubFormControl(Me).Name
End Sub

Same technique can be used with multiple instances of forms.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top