Filter query based on the combobox/textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sandy1992
    New Member
    • May 2015
    • 57

    Filter query based on the combobox/textbox

    Hi friends,

    I am using A2010. I have completed preparing the whole application but stuck with reports.

    what I want to do:

    There is 1 command button and 1 textbox/combobox(happy if works with any of the control) . When I type employeeId(whic h is numeric) in that control and click on command button, it should filter the query and display the result in report. It sounds easy , but not for me. I tried lots of ways to get it done. But from past 6 days stuck with this.

    I am using query to fetch data in unbound combobox.

    SELECT tblUserqry.[EmployeeId] FROM tblUserqry;

    And below criteria in query:

    Like [Forms]![Form3]![EmpID]

    'EmpID is name of combobox

    At last below Macro for onclick , that opens the query in datasheet .


    Please note that I don't know how filter works in ms access. All types of suggestions are accepted.

    I need to complete it ASAP.

    Please help.

    Looking forward for participations.
    Last edited by zmbd; May 26 '15, 01:44 PM. Reason: [z{placed a few code tags :) }]
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Sandy1992,
    First, let me quibble with your wording. You say you are stuck on 'reports' but you then describe a problem with opening a query. Viewing query results is not viewing a report; they are different things. I think there is no report involved. Please correct me if I am wrong.

    Further, you don't tell what the problem is. You have button that runs this macro. The macro opens a query. It is not clear what the name of that query is. You describe this other(?) query:
    Code:
    SELECT tblUserqry.[EmployeeId] FROM tblUserqry;
    and then you describe a where clause
    Code:
    Like [Forms]![Form3]![EmpID]
    Is that where clause part of the combobox query? That wouldn't make sense, so I think it must be part of the query the macro opens. And that looks pretty good, like it should work.

    What happens when you click the button? You don't tell what result you are getting.

    I think what you need to do is pretty simple. Getting help "asap" on this website should not be a problem if you will restate your problem clearly and completely. Give us more detail.

    And congratulations on sticking with it. Six days fighting a program is frustrating.

    Jim

    Comment

    • Sandy1992
      New Member
      • May 2015
      • 57

      #3
      Thanks a lot for your response. But I solved my problem :)

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Sandy1992,
        Very happy you solved your problem; however, perhaps you would be willing to share so that others may potentially benefit from your experience?

        Comment

        • Sandy1992
          New Member
          • May 2015
          • 57

          #5
          Yeah Sure,

          I will more than happy if I can help. :)

          what I did is simple.

          I used combobox to fetch the data to filter my form.

          In Property window, under Row Source I used
          Code:
          SELECT [AddUser].[ID], [AddUser].[EmployeeId] FROM AddUser;
          This way my combobox was displaying the data which I wanted.

          Now, I used a subform to show the filtered result in it.

          I created a query and on the field I really wanted to filter I used :
          Code:
          Like [Forms]![Searchbyemployeeid]![EmpID]
          And lastly, on Combobox -> after update I used code :
          Code:
          Private Sub cboEmployee_AfterUpdate()
           Dim Myemp As String
              Myemp = "select * from Tasks where ([EmployeeId] =" & Me.cboEmployee & ")"
              Me.Tasks_subform.Form.RecordSource = Myemp
              Me.Tasks_subform.Requery
              
              
          End Sub
          Try it out. Simple and fun :)

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            thnx you.... you might take a look at our Insights articles. There are several examples of filtering methods:

            Comment

            Working...