Can I programmatically change a Subform’s Child/Master link with a

E

efandango

I have a continuous Subform linked to a main form via a query. I want to be
able to hit a button that will effectively switch on/off the child/master
link so that the results will relate to the individual Main record or all the
main records depending if the button is pushed. Can this be done?
Alternatively can I with a button on the form change the criteria of the
query? if so, how would I code for that?

The Master/Child field is called [Run_No]

The main Form is called ‘Runs’ and the Subform is called
‘frm_Waypoints_Results’
 
S

Stefan Hoffmann

hi,
The Master/Child field is called [Run_No]
The main Form is called ‘Runs’ and the Subform is called
‘frm_Waypoints_Results’

FormSetSubForm frm_Waypoints_Results, _
frm_Waypoints_Results.SourceObject, _
"Run_No", "OtherField"

or

FormSetSubForm frm_Waypoints_Results, _
frm_Waypoints_Results.SourceObject, _
"", "", False

Place this in a normal module:

Public Sub FormSetSubForm(ASubForm As Access.SubForm, _
ASourceObject As String, _
ALinkChildFields As String, _
ALinkMasterFields As String, _
Optional ALinkMasterChild As Boolean = True)

On Local Error GoTo LocalError

If ASubForm.SourceObject <> ASourceObject Then _
ASubForm.SourceObject = ASourceObject

If ALinkMasterChild Then
If ASubForm.LinkChildFields <> ALinkChildFields Then _
ASubForm.LinkChildFields = ALinkChildFields
If ASubForm.LinkMasterFields <> ALinkMasterFields Then _
ASubForm.LinkMasterFields = ALinkMasterFields
Else
If ASubForm.LinkChildFields <> "" Then _
ASubForm.LinkChildFields = ""
If ASubForm.LinkMasterFields <> "" Then _
ASubForm.LinkMasterFields = ""
End If

Exit Sub

LocalError:
'Do error handling. Normally not necessary.

End Sub


mfG
--> stefan <--
 

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