Filter table from VB Code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ChaseCox
    Contributor
    • Nov 2006
    • 293

    #1

    Filter table from VB Code

    Is there a way to filter tables in a Database with only VB Code, or do you have to use the queries? If this is possible I would like to eliminate my queries and filter the tables in my database with just code. I would also like the results to be output to a new table in the database and maybe to an excel file. I have no idea how this would work, so I will need alot of help if this is possible. I would like to use my form to still pass the values in.
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Basically You need a query with criteria to filter a table.
    Changing such a query into a MakeTable query will create a filtered copy.

    Filtering from code is done on a form, e.g. a master form with a datasheet subform.
    There the right-click (also usable on a table) can be used to filter with an AND relation, or the FilterByForm button when an OR relation is needed.
    In code you can also apply a filter with:

    Me.subformname. form.filter = "ID=" & me.ID
    Me.subformname. form.filteron = True

    Such a filter (and a right-click filter) can be added as a WHERE clause to a query created in code.

    Nic;o)

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      Originally posted by ChaseCox
      Is there a way to filter tables in a Database with only VB Code, or do you have to use the queries? If this is possible I would like to eliminate my queries and filter the tables in my database with just code. I would also like the results to be output to a new table in the database and maybe to an excel file. I have no idea how this would work, so I will need alot of help if this is possible. I would like to use my form to still pass the values in.
      Although you could implement a sort of filtering in VB code it would not serve your purpose well. The result would only be available to your code for a start, which would need to be developed further to output the results somewhere accessible. It really has many drawbacks, not least of which is the inefficient execution.
      I'm curious as to why you would want to bypass one of the (possibly the most) fundamental tools of database manipulation and processing?

      Comment

      Working...