MarkK
bit cruncher
- Local time
- Today, 10:22
- Joined
- Mar 17, 2004
- Messages
- 8,431
An Access.Form object exposes a Filter property that you can use like a WHERE clause. In that case the syntax is like ...
I don't use Form.Filter much, so maybe you don't need to explicitly set the FilterOn after setting the text. Not sure.
An sort of unrelated observation I have of code you posted is that it runs a process in a different object using data and controls in that object. Typically you want to make each object responsible for itself, responsible for it's own functionality and it's own data.
Think about this. Put a Public Sub on the parent form, and teach consumers of that parent to call that Sub to change out Subform2. Imagine this code on the parent ...
... and now the child form button click consumes the new Public method exposed by the parent ...
... or consumers can just unload the subform on the parent ...
... so if work has to happen in the Parent, teach the parent to do it for itself, then any child can make it happen with one line of code. Simpler. More stable. More scalable. Each object fends for itself.
Code:
Me.Filter = "Fieldname = " & fieldValue
Me.FilterOn = True
An sort of unrelated observation I have of code you posted is that it runs a process in a different object using data and controls in that object. Typically you want to make each object responsible for itself, responsible for it's own functionality and it's own data.
Think about this. Put a Public Sub on the parent form, and teach consumers of that parent to call that Sub to change out Subform2. Imagine this code on the parent ...
Code:
Public Sub ChangeOutSubform2(sfmName as String)
[COLOR="Green"]' loads or unloads a form from the SF2Cont subform control
' and sets or clears the filter on Me as the case may be
[/COLOR] Me.SF2Cont.SourceObject = sfmName
If sfmName <> "" then
Me.Filter = "FID = " & Me.SF1Cont.FID
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End Sub
Code:
Private Sub Tab2ButtonLabel_Click()
Me.Parent.ChangeOutSubform2 Me.Tab2FormName
End Sub
Code:
Private Sub UnloadButton_Click()
Me.Parent.ChangeOutSubform2 ""
End Sub