How to find the name of the present subform

A

Access infant

Hi All,
I have a problem with finding the name of the present subform in the main
form. Before coming to the problem,let me give a background of the design
Actually every first level subform is unbound and they hold one or two
second level subforms which are bound to tables and are in one- to- many
relation with the mainform. And every level1 subform has two navigation
buttons ".Next > ", "< Back ". the code in the click event of these buttons
see what form follows next. The code is as follows.
Me.Parent.sfrmholder.SourceObject = "sfrm to come next" etc...

Now i want the second level forms to display records related to the record
in the main form. the code is i used in the current event of the main form is:
Me!sfrmholder.Form!sfrm11.Form.Filter = "EmpSid = " & Me.txtEmpSId
Me!sfrmholder.Form!sfrm11.Form.FilterOn = True
Me!sfrmholder.Form!sfrm11.Form.Requery
it works perfectly well if i display only one subform. but the subforms
change one by one as in a control wizard in access. so, my idea is to find
the name of the subform in a select case statement and depending of the
present subform i want to take action accordingly. it is something like
Private Sub Form_Current()
Select Case Me!sfrmholder.Form.Name
Case sfrmOldIncrements
Me!sfrmholder.Form!sfrm2.Form.Filter = "EmpSid = " & Me.txtEmpSId
Me!sfrmholder.Form!sfrm2.Form.FilterOn = True
Me!sfrmholder.Form!sfrm2.Form.Requery
case XXX
Me!sfrmholder.Form!sfrm2.Form.Filter = "EmpSid = " & Me.txtEmpSId
Me!sfrmholder.Form!sfrm2.Form.FilterOn = True
Me!sfrmholder.Form!sfrm2.Form.Requery

End Select
End Sub
But this is not working.can any one tell me how to do this? If i get the
name of the subform, i can continue with the above code. I am quite hopeful
of a solution!!!! please tell me how to solve this
 
D

Douglas J. Steele

I'll assume that that's not really what you want to do (since you've got the
same code regardless of which form is being used as the subform...)

Look at the SourceObject property of the subform control. Remember that the
property is text, so you names need to be in quotes:

Private Sub Form_Current()

Select Case Me!sfrmholder.SourceObject
Case "sfrmOldIncrements"
Me!sfrmholder.Form!sfrm2.Form.Filter = "EmpSid = " & Me.txtEmpSId
Me!sfrmholder.Form!sfrm2.Form.FilterOn = True
Me!sfrmholder.Form!sfrm2.Form.Requery
Case "XXX"
Me!sfrmholder.Form!sfrm2.Form.Filter = "EmpSid = " & Me.txtEmpSId
Me!sfrmholder.Form!sfrm2.Form.FilterOn = True
Me!sfrmholder.Form!sfrm2.Form.Requery
End Select

End Sub
 
A

Access infant

Thank you, Douglas
It worked well. I actually tried the same at first but failed to get the
result until you pointed that i should put the subform name in quotes. Thanks
a lot and lot
 
A

Access infant

Mr.Marsh,
your suggestion is quite interesting but i don't know how to do this. could
you please explain to me in detail. Actually the level1 subform is unbound so
no question of linking fields arises. So, please tell me how i can link the
subsubform directly with the mainform. I confuse where i should put the
following code:
Forms!mainform.linkfield
Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top