Query Display List for Criteria

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ckpoll2
    New Member
    • Sep 2006
    • 76

    Query Display List for Criteria

    I'm trying to make it so that instead of having to type criteria in a query using [Enter Component Name], the user is asked to select a component from a list that pops up when they run the query. Is there VB code that can do this? I need to pull the list from tblAgency Names for use in qryComponents. I would appreciate any help you all can provide.

    Thanks in advance for your help!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32636

    #2
    Charlie isn't it?
    It can certainly be done. We would need some more details and explanation from you before proceeding though. The question is easy enough. The answer requires a better understanding of what you want to do.

    Comment

    • ckpoll2
      New Member
      • Sep 2006
      • 76

      #3
      Thanks for the reply.

      Basically, what I need to do is have a list of selections pop up rather than a text box to enter data.

      I've built a query (named Recon by Agency) that will return data for one particular agency that the user specifies. The problem is that they may spell it wrong or forget the name of the agency. Therefore, I'd like to have them select the agency (stored in table Agency Names) from a list that will appear after they click on the "run query" button rather than typing it themselves into a box that pops up.

      I'm sure that this can be easily solved using some VB code, but I'm still very unfamiliar with VB. Any help that you could give me would be very much appreciated. Let me know if there's any other information that you need.

      Sorry to keep bugging you guys with this. You're immensely helpful.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32636

        #4
        Getting code to run once (and only once) after you've invoked your query is actually quite hard to do (if indeed possible).
        For your scenario, a form with a prepopulated ComboBox would probably do the trick better. This isn't an exact answer to your question, but may well be the best alternative.
        You create a form which includes the ComboBox as well as a Command Button. Have the user select the required item from the ComboBox then hit the Command Button. The code behind the Command Button would have to create a new QueryDef (saved query) with the SQL from the original but doctored to change (or supply) the WHERE clause.
        If it was not required simply to open as a view for the operator, your options are better. Unfortunately, There doesn't seem to be an option either to open a QueryDef and also apply a filter, nor one to open a SQL string for view by an operator.
        Most other requirements can be met by simply doctoring the SQL and using the newly created SQL.

        Comment

        Working...