Filtering a continuous form

branston

Registered User.
Local time
Today, 09:12
Joined
Apr 29, 2009
Messages
372
I have a continuous form. In the form header I have put a combo box. I want the combo box result to filter which records are shown in the continuous part of the form. So far i have:

Me.ComboDisp.SetFocus
DoCmd.RunCommand acCmdFilterBySelection

but its saying "The command or action "FilterBySelection" isnt available now.
Is there a reason for this??

Thanks!
 
Is there a reason for this??
Probably, but there is a better way. Use this code instead:

If the field is numeric you will need:
Code:
Me.Filter = "[YourFieldNameToFilterOn]=" & Me.ComboDisp
Me.FilterOn = True

If the field is text you will need:
Code:
Me.Filter = "[YourFieldNameToFilterOn]=" & Chr(34) & Me.ComboDisp & Chr(34)
Me.FilterOn = True

If the field is a date:
Code:
Me.Filter = "[YourFieldNameToFilterOn]=#" & Me.ComboDisp & "#"
Me.FilterOn = True

And to remove the filter:
Code:
Me.Filter = ""
Me.FilterOn = False
 
Use the combo box Wizard, it'll write the code for you
 
Thanks boblarson, worked great. Much better than my way!
 
I have a continuous form. In the form header I have put a combo box. I want the combo box result to filter which records are shown in the continuous part of the form. So far i have:

Me.ComboDisp.SetFocus
DoCmd.RunCommand acCmdFilterBySelection

but its saying "The command or action "FilterBySelection" isnt available now.
Is there a reason for this??

Thanks!

The docmd isnt the answer you need. You should look to use something like this:


Dim sProcessId
With Combo9 'Combo Box Name
If .ListIndex <> -1 Then
'sProcessId = .SelText
'Retrieves the value of the bound column which may more may not be
'displayed in the list box
sProcessId = .Column(.BoundColumn - 1)
Filter = "IDNUmber=" & sProcessId
FilterOn = True
MsgBox "Filter Applied"
End If
End With

Hope this helps!
trevorg
 

Users who are viewing this thread

Back
Top Bottom