I have a database that has 3 tables (ListOfDevice, DeviceType, Employee).
ListOfDevice Table
- DeviceName
- Device Model
- DeviceType ------> Referenced to the DeviceType table using ID and DeviceType.
- EmployeeID ------> Referenced to the Employee table using ID and FirstName.
- DeviceStatus ------> This only have two values either Working or Damaged.
Some of the record does not have employeeID, and those are labelled "Damaged" on the device status field.
I created a query and named it as "QryDeviceLists" and inside this query I imported those 3 tables and begin filtering for the query and report result. I used the "Like" and Wildcard for filtering.
Example: Like"*" &[Form]![FormName]![ControlName or Combo box name]&"*"
What I'm trying to filter here is the DeviceType, EmployeeID and the DeviceStatus. And the way I want this filter to work is through combo boxes, I have a form which I named as filter and inside this form is 3 unbound combo boxes linked to the those 3 tables. And here is how I will generate a report:
If I select a value from the devicetype combobox either "Desktop or laptop" and leave the other combo boxes blank then, it should give me a result of either laptop or desktop with all the users and the device status whether working or damaged.
The same for the EmployeeID combo box, if I selected a name or employee ID it should give a result of the specific device assigned specifically for that employee.
And for the device status combo box, it should give a result either working or damaged depending on the selection from the combo box.
And by leaving all the combo boxes blanks it should show all the record of the devices whether it's a laptop or desktop, working or damaged, assigned to all employees.
Here are the problems which I'm facing when trying to pull out a report using the combo boxes.
If I select a value from the Device Type and leave the employee ID and Status as blank, no records are showing. Same problem goes to Employee ID Combo Box, If I leave the Device Type and Status as blank, also no records are showing.
If I leave all the combo boxes blanks then only the records which are labelled as Working on the Device Status are showing. This is maybe because the other record which is labelled as Damaged has no value on the employee ID field. Because when I tried to put a value inside the Employee ID field and regenerate the query by leaving all the combo boxes empty then all the records show up.
Note: I don't have any VBA experience, and I'm using Access 2013-2016
Here are the query SQL Lines SELECT ListOfDevices.ID, ListOfDevices.DeviceName, ListOfDevices.[Device Model], DeviceType.DeviceType, Employee.FirstName, ListOfDevices.DeviceStatus
FROM Employee RIGHT JOIN (DeviceType RIGHT JOIN ListOfDevices ON DeviceType.ID = ListOfDevices.DeviceType) ON Employee.ID = ListOfDevices.EmployeeID
WHERE (((DeviceType.DeviceType) Like "*" & [Forms]![filter]![CboDevType] & "*") AND ((Employee.FirstName) Like "*" & [Forms]![filter]![CboEmp] & "*") AND ((ListOfDevices.DeviceStatus) Like "*" & [Forms]![filter]![CboStat] & "*"));