Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VBA to Filter a Query

Status
Not open for further replies.
Feb 1, 2001
116
US
I have a query embedded into a form. When I open the form I would like to filter the criteria of one of the columns in the query using VBA, but I am having no luck.

Any pointers?
 
Have a look at the Filter and FilterOn properties of the Form.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I have tried:

DoCmd.ApplyFilter , "[Structure Name] = '555'"

It accepts the filter, but as I look at the embedded query, nothing changes in the "Structure Name" field.
 
This is really getting frustrating. I have a Query called "PhotoList_Query" that 3 fields called "Structure Number", "Filename" and "Description". I have a Form that has a Listbox with the query as it's source object.

I am trying to open the Form and filter the Listbox to only show specific items in the "Structure Number" field. This will change as per the what structure (Bridge) the user selects. I am trying a DoCmd.ApplyFilter and the Listbox does not reflect the filter.

DoCmd.ApplyFilter "PhotoList_Query", """555"""

Any help ould be great. I would even consider reading the content from the Query into a list box each time the form opens if I can find VBA code on how to do this.
 
A ListBox, AFAIK, has NO source object but a RowSource property.
I don't see how filtering a Form should also filtering a ListBox.
Can't you dynamically build the SQL code of the ListBox's RowSource in the Load event procedure of the Form ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Wow, well probably if I had a clue on how to do that. Sorry to be such a Pod.
 
Ok, after messing with it some more, you are right. What I have in my Form is not a ListBox, but I have embedded the query tiself into the Form. I would like tha user to make changes and input data right into the query, but I need to filter the data in the query everytime the Form opens.
 
I have embedded the query tiself into the Form
???
A subform in DataSheet view ?
 
Yes, why is that a "no no"? I'm sure it shows that I'm not a dbase person. I've been writing in VB for years, but my work needed some work in Access so here I am plodding through this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top