How can I code a command button to ask for the parameter for a filter?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jesse Jones
    New Member
    • Jan 2011
    • 51

    How can I code a command button to ask for the parameter for a filter?

    I would like to place a command button on a form that would ask for a client id and then pull up that clients record. (Essentially, all it has to do is filter the [Client ID] field to whatever parameter the user enters.

    I would think this pretty simple, but I'm afraid I don't know how to do it.

    Any help would be greatly appreciated.

    Thanks.
  • colintis
    Contributor
    • Mar 2010
    • 255

    #2
    Use the command button to run a query, then in the query you used to extract the record, place any name to the WHERE condition with the CLientID will do.
    Code:
    SELECT xxx FROM xxx
    WHERE ClientID = [Enter Client ID]
    This will pops up a message box to ask for parameter

    Comment

    • Jesse Jones
      New Member
      • Jan 2011
      • 51

      #3
      I'm sorry. I'm too much of a newb to understand that. I'm sorry.

      What should I put in an on click event in VBA?

      I'm sorry.

      Comment

      • colintis
        Contributor
        • Mar 2010
        • 255

        #4
        You can first create a query in SQL view for a test, such as
        Code:
        SELECT ClientName, ClientAddr
        FROM tblClient
        WHERE ClientID = [Enter ID]
        Notice [Enter ID] is something that does not exist in any tables at all, when execute Access will pop up a window box and ask an input for [Enter ID].

        This can also be done in the design view as dragging the necessary fields, and place "[Enter ID]" as criteria.

        Once its done, in the buttom on click event, you can either use macro that is more simply click and select to open the query you made earlier. Or in VBA, place a line of code like this
        Code:
        docmd.runquery ("<name of the query>")
        If you still don't understand some terms or making query, please do google search on "Access tutorial".

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          What you need to do is first to get the information from the operator. This can be done in many ways, from the simplest of using InputBox(), through doing something very similar with a modal form and a TextBox, all the way through to a more sophisticated form using a ComboBox to select from the valid existing items in your recordset.

          I guess from how your question is framed, that you already know how to form and apply this in a filter. If not, let us know so we can explain further.

          Comment

          • Jesse Jones
            New Member
            • Jan 2011
            • 51

            #6
            Got it. Pretty simple. Thanks.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32656

              #7
              Good for you :-)

              Comment

              Working...