Form/Subform Coding - HELP Needed

  • Thread starter Thread starter New Guy
  • Start date Start date
N

New Guy

I have a form with a subform using both Master and Linked Child fields. I
want to change the Linked Child Field based on a value in a checkbox (0 or
-1). Any CODING ideas would be appreciated.
 
New Guy said:
I have a form with a subform using both Master and Linked Child fields. I
want to change the Linked Child Field based on a value in a checkbox (0 or
-1). Any CODING ideas would be appreciated.

Retrieve the checkbox value then the following code could be useful:

Public Function displayVarform(strmainform, strSubformcontrol,
strControlname, strChildFields, strMasterFields, strRecordsource)

Call bindvarform(strmainform, strSubformcontrol)
Forms(strmainform)(strSubformcontrol).SourceObject = (strControlname)
Forms(strmainform)(strSubformcontrol).SourceObject = (strControlname)
Forms(strmainform)(strSubformcontrol).Form.RecordSource = (strRecordsource)

On Error Resume Next
Forms(strmainform)(strSubformcontrol).LinkMasterFields = strMasterFields
On Error Resume Next
Forms(strmainform)(strSubformcontrol).LinkChildFields = strChildFields

End Function

Private Sub Toll_Fees_Click()

strmainform = Me.Form.Name
strSubformcontrol = "varform"
strControlname = "frmTripExpensesDetails"
strChildFields = "tabTripHeaderID"
strMasterFields = "tabTripHeaderID"
strRecordsource = "tabTripExpenses"

Call displayVarform(strmainform, strSubformcontrol, strControlname,
strChildFields, strMasterFields, strRecordsource)

If frmState = 1 Then

Call displayVarform(strmainform, strSubformcontrol, strControlname,
strChildFields, strMasterFields, strRecordsource)
Call bindvarform(strmainform, strSubformcontrol)

ElseIf frmState = 0 Then

strmainform = "frmTripHeader"
strSubformcontrol = "varform"
strControlname = "frmTripExpenses"
strChildFields = ""
strMasterFields = ""
strRecordsource = ""

Call displayVarform(strmainform, strSubformcontrol, strControlname,
strChildFields, strMasterFields, strRecordsource)
Call unboundvarform(strmainform, strSubformcontrol)

End If


End Sub

Alternatively, you could create an sql statement and use it as the
recordsource for the subform and forget about the link fields. Both works
fine.

Private Sub SatTrack_Click()

'Me!varform.Visible = True

strmainform = "frmHorses"
strSubformcontrol = "varform"
strControlname = "frmSattrackDetails"
strMasterFields = ""
strChildFields = ""
strRecordsource = "select * from tabsattrack where tabHorseID = " &
Forms(strmainform)!HorseID & ";"

Call displayVarform(strmainform, strSubformcontrol, strControlname,
strChildFields, strMasterFields, strRecordsource)
Call bindvarform(strmainform, strSubformcontrol)

End Sub

I experienced some linking problems with subforms and child fields so I used
the sql statements.

I hope this is useful.
 
Back
Top