|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Filter Multi SubForms from the mainform filter
Hi DBer's
Here's one for the books! How u set a combo (unbound) box to pull up names from records that when the selection is chosen the subforms filter the said choice. The subforms are link master & child SchedID. Thanks MCB |
|
#2
|
|||
|
|||
|
One way is to set the Filter and FilterOn properties of the subforms.
In the AfterUpdate of the combo you'll need code like: Me!SubformControlName.Form.Filter = "SubformFieldName = " & Me!ComboBoxName Me!SubformControlName.Form.FilterOn = True Don't forget that if the field you're filtering isn't numeric you will need to adapt the filter string: For text: SubformFieldName = '" & Me!ComboBoxName & "'" For dates: SubformFieldName = #" & Format(Me!ComboBoxName,"m/d/yy") & "#" |
|
#3
|
|||
|
|||
|
Thanks, with a little tweaking it worked!
Now that I have this code right Me.GMon8a.Form.Filter = "Technician = '" & Me.Combo569 & "'" Me.GMon8a.Form.FilterOn = True If say I need to add a second field name to the filter, how would it added? Last edited by WarriorMCB : September 29th, 2009 at 12:21 AM. |
|
#4
|
|||
|
|||
|
You can just concatenate, eg:
Code:
With Me.GMon8a.Form .Filter = .Filter & "And SecondField = '" & SecondCombo & "'" .FilterOn = True End With Be aware that this will cause you problems if there's not already something in the filter. If you have a number of filtering combo boxes I suggest a slightly more robust method that also makes it easier to empty out the filter. In the main form module, add a sub like: Code:
Private Sub FilterSubform()
With Me.GMon8a.Form
.Filter = ""
.FilterOn = False
If Not IsNull(Me.Combo569) Then .Filter = "Technician = '" & Me.Combo569 & "'"
If Not IsNull(Me.SecondCombo) Then
If .Filter <> "" Then .Filter = .Filter & " And "
.Filter = .Filter & "SecondField = '" & SecondCombo & "'"
End If
If Not IsNull(Me.ThirdCombo) Then
If .Filter <> "" Then .Filter = .Filter & " And "
.Filter = .Filter & "ThirdField = '" & ThirdCombo & "'"
End If
If .Filter <> "" Then .FilterOn = True
End With
End Sub
Keep adding to this sub for each combo. Then you need AfterUpdate code for every sub: Code:
Private Sub Combo569_AfterUpdate()
FilterSubform
End Sub
Repeat for each combo in the FilterSubform sub. This method also works for text boxes used for filtering. There is a character limit for filter strings. I can't remember for definite but I think it's 256 characters. You're unlikely to hit the limit using this method. Note that the FilterSubform sub is Private; this means that other subs in the smae module can use it, but subs in other modules cannot see it at all. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Filter Multi SubForms from the mainform filter |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|