0
votes

I have a form (form1) . I have a report (report1), and this report has 4 fields:

  • ID
  • NameEmp
  • dataHiring
  • Salary

I need to filter this report based on user choices from a combo box (named cboname) in form1.

How to set a filter for report1 that contains only NameEmp based on cboname?

I already tried to use this VBA code:

DoCmd.Setfilter Where condtion :- [NameEmp]= forms!Form1 [cboname]
Event: On Open_Report1

thanks a lot.

1
Welcome to StackOverflow. You should consider reading the How to Ask guide before asking a question. For more information about the site, you can visit the tour page. - Zac Webb
Sorry, but that code you posted isn't VBA (at least, it violates multiple syntax rules of VBA). That makes it hard for me to understand what you are trying to do and troubleshoot your code. Try to first follow a VBA tutorial before you try to integrate VBA code into your database. - Erik A
thanks, Mr.Erik, but I am nope in VBA code, what I am trying to say: that I want to set a filter to my report based on user choices, by using a combo box. so if the user chooses the first choice then the report will be filtered according to this choice, but also if the user does choose anything the report will open with all information without any filtering. that's all. - Iroyal

1 Answers

0
votes

make a query to the report and under ID criteria put [forms]![form1]![cboname]

thanks for helping, but still that is not what I want because if I want to build many combo boxes, that's mean I have to build many queries for many combo boxes. and Second: see the example down : if I build a query with multiple fields let say ( and I will put your criteria in front of each field ):

  1. ID [forms]![form1]![cbonID]
  2. NameEmp [forms]![form1]![cboname]
  3. dataHiring [forms]![form1]![cbodataH]
  4. Salary [forms]![form1]![cboSal] the access will run the query according to criteria, now I understand that clearly, but, what if the user want all employee name with hiring data before 2012. what if also the user choose all salary above 3000$ with all information (ID, NameEmp,dataHiring).. and so on. Multi-choices for one report, that's mean a many queries!!!
    all I want to set filter and if the user does not choose anything then remove applied filter.