Filter by selection in VBA code

PeterOC

Registered User.
Local time
Today, 17:47
Joined
Nov 22, 2007
Messages
80
I'm just wondering how I can recreate the functionality of the filter by selection button in vba. I can determine which control the user is selecting but how do I get from that to the control source. There's no control source property in ActiveControl?

Thanks
Peter
 
Don't use the ActiveControl property. Use the name of the control. For example, a textbox named txtMyTextbox is:

txtMyTextbox.Value
 
How about this in the command button:
Code:
     Screen.PreviousControl.SetFocus
     DoCmd.RunCommand acCmdFilterBySelection
 
Thanks both for the feedback. I'm trying to use a filter by selection in an adp and some sub-totals are not updating when I apply a filter. I found out that this is because of the way access fetches data from the sql server but I'm not sure how to get around this.
 
Problem

Hi All
I have a little problem.
I have in access 2002 two combo boxes and I would like to use them both to create a filter on that form, but it only works with one combo box. How to wright code for filter with two combo boxes as conditions?:confused:
 
Hi All
I have a little problem.
I have in access 2002 two combo boxes and I would like to use them both to create a filter on that form, but it only works with one combo box. How to wright code for filter with two combo boxes as conditions?:confused:

Welcome to Access World Forums. It would have probably been more efficient for you to start a new thread rather than add to a post that already has many posts. Alot of people won't even look at them as they figure a separate conversation is going on.

As for filtering you can use on a command button's click event:

Code:
Me.Filter = "[YourFieldNameHere]=" & Me.YourComboBox1 & " And [YourOtherFieldNameHere] = " & Me.YourComboBox2

If any of them are text you need to qualify with single quotes inside double quotes. For example, let's say that the first combo box is a number and the second one is text. That would be:

Code:
Me.Filter = "[YourFieldNameHere]=" & Me.YourComboBox1 & " And [YourOtherFieldNameHere] = [color=red][b]'[/b][/color]" & Me.YourComboBox2 [color=red][b]& "'"[/b][/color]
 
BIg BIg thankssssss!

This WORKS.... YUHUUUUUU!
Thank you Bob for a quick and accurate answer.....
Best Regards Bob....:):):):):):):D
 
Bob, just wondering if you can help me with what is a bit of a continuation from the original question. I've been looking all over the internet for the answer to this and the one solution I did come across didn't make sense to me but I can't find where I found it originally anyway.

I'm working on an adp and found out that adp's don't filter the same way mdb's do. I have a subform with column totals for a number of columns. When this is filtered the sub-totals don't update. I'm sure the 'solution' I found mentioned using a server filter instead but I've been trying various ways of doing this without success.

There's also a report that prints based on the filter on the subform and I need to have updated totals on this aswell. Can you give me any advice.

Many thanks,

Peter
 
Bob, just wondering if you can help me with what is a bit of a continuation from the original question. I've been looking all over the internet for the answer to this and the one solution I did come across didn't make sense to me but I can't find where I found it originally anyway.

I'm working on an adp and found out that adp's don't filter the same way mdb's do. I have a subform with column totals for a number of columns. When this is filtered the sub-totals don't update. I'm sure the 'solution' I found mentioned using a server filter instead but I've been trying various ways of doing this without success.

There's also a report that prints based on the filter on the subform and I need to have updated totals on this aswell. Can you give me any advice.

Many thanks,

Peter
I'd suggest posting it as a separate question. I don't use ADP's, so I wouldn't know what to tell you.
 
question again!

Thanks again Bob! It really helped me.
I wondered, if you could help me something connected to the last question.
I created a form and one text box on it for the filter and a command button for the filter. Everything works great with filter but I would like to use the same text box to use the filter again but not to lose previous filter (filter on filter).
I tried like this:

Dim Filtika As String
If Me.FilterOn = True Then
Me.Filter = Filtika
Me.Filter = "[myfieldname] = '" & Me![mytextboxname] & "' And Filtika"
Me.FilterOn = True
Else
Me.Filter = "[myfieldname] = '" & Me![mytextboxname] & "'"
Me.FilterOn = True
End If

But with no result
Thanks in advance
 
new treat?

Anyway Bob, I do not know how to post a new treat....
I do not have that option....
Thanks! :)
 
Anyway Bob, I do not know how to post a new treat....
I do not have that option....
Thanks! :)

awfnewthread.png
 
Im doing Database from Ms Access 2013 and I need to automatically filter. i did it manually, but automatically i can't. Please help
 
Hi All
I have a little problem.
I have in access 2013 five combo boxes and I would like to use them both to create a filter on that form, but it only works with one combo box. How to wright code for filter with two combo boxes as conditions? :(:(
and how i sorting ike in excel to A to Z please help
 

Users who are viewing this thread

Back
Top Bottom