Question : Setting LinkChildField and LinkMasterField Property Issue

I inherited an application which I am trying to increase the efficiency on.  One form had approx. 20 subforms on it.  They were all set to visible = false until a command button was pushed by the user selecting which subform to show.  The problem is it took the form a long time to load since it was loading all 20+ subforms on open.  Also since the user may open the main form and only need to ever use one of the subforms anyway, I thought it would be best if I just put one Subform, then when the user pushed the button for subfom selection, I would just set the recordsource property on the subform.  Below is the code I am using, and here is the problem I am having.  The LinkChild field, Link Master field is not working correctly.  All records are being displayed in the subform.

I have an option group.  It's code looks like this:
 Select Case optGroup
        Case 1
            PopulateSubForm "frmBidKO_ControlDocList", "sTop", "JobNumber"
        Case 2
            PopulateSubForm "frmBidKO_OpeningStmt", "sFull", "JobNumber"
       etc......

My PopulateSub Form Function does this:
Sub PopulateSubForm(strSourceObj As String, strLinkChild As String, Optional strLinkMaster As String)
         Me.subFormFull.SourceObject = strSourceObj
         Me.subFormFull.LinkChildFields = strLinkChild
        If Not IsMissing(strLinkMaster) Then
            Me.subFormFull.LinkMasterFields = strLinkMaster
        Else
            Forms(strSourceObj).CONTROLS(strLinkChild).DefaultValue = Me.JobNumber
        End If
        Me.subFormFull.Visible = True
        Me.subFormFull.SetFocus


Just an FYI, in case you are wondering why I use the subfunction or why the subformfull.visible has to be set to true, is that there is some more code that I have not posted because I believe it is irrelavant.  I basically have three subforms, one large one (subFormFull) and then two small ones (subFormTop and subFormBottom).  There are a few subforms, that need the large subform, but there are a few where two subforms are displayed so I have two half size ones I use.  The code is set to also pass which subform to use, and the other subform(s) are set to visible = false and their recordsource set to = "".  I know that part of the code is fine, because the subforms are populating with the proper recordsources, the LinkChild LinkMaster fields just aren't working.

REALLY NEED HELP ASAP.... been fighting this for too long... GRIN !!

Answer : Setting LinkChildField and LinkMasterField Property Issue

Remove parent/child links.  Instedad, in each subform recordset SQL under child field to be, enter:

if [CustID] for that subform:  fnCustID()

With a function call:

Function fnCustID() ' As Long
   fnCustID=Forms!fMainForm!txtCustID
End Function

And, in the on current event of fMainForm, have

Me!SubFomControl.Form.Requery

Mike
Random Solutions  
 
programming4us programming4us