Change the query criteria and run it from a form using VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ahmed Nada
    New Member
    • Oct 2013
    • 1

    #1

    Change the query criteria and run it from a form using VBA

    Hi,
    I have small data base with many tables, one of them a table for equipment wit related details, as below fields.

    1-EqipmentID
    2-SerialNO
    3-Model
    4-Coustmer
    6-City

    I created one normal method query of ACCESS “QueryEQ” on that table , but every time I want to change any criteria I have to edit manual direct to query design .

    What I need to do now is to create a form with one combo box showing all “model” and after select any mode I have to press command bottom to change the criteria of the model of the existing query “QueryEQ” and run it and show the result in a subform in same form.

    Any idea how to that using VBA

    thank you in advance
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    If you are only changing the model in the query, then all you need to do is reference the combo box in the query instead of hard coding in the value you are wanting. Then the query will search for the model that you select without having to change the query at all.

    However, if you are making bigger changes than that (like which field is in your criteria) then here is a link to show you how to change the SQL code in your query using VBA: QueryDef.SQL Property (DAO)

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      Queries III: Create parameter queries that prompt users for input
      This may be for Access 2003; however, the method hasn't really changed in many many years.

      You might find this helpful as well: MS Access 2010 Tutorials

      Comment

      Working...