I have a problem I've been trying to fix for the past two weeks.
I'm trying to create a search form which filters :
--Customers first name, last name, organization, shop name, office symbol
--Building Name, Room Name
--Equipment name, equipment serial number, equipment IP address
Each search box is a combo box. A user can filter by one combo box, or by several. So there is " AND " between each if statement.
At first I used a union query and set that query as the recordsource for the form. I needed it to be a union query due to the fact that customers could be a building POC or a room POC and I need to search through both. Also I need it to be an actual query (as opposed to a simple SQL statement in VBA code) because I need to use DCount to count records and tell the user if there are no results.
The problem w/ using one main query is that there are duplicate results in the form recordsourse. Like if Michael Smith, Andy Jones, and John Doe own BuildingFK 1, RoomsPK 10, if I filter by BuildingFK 1, RoomsPK 10 I will see 3 records.
Now, the purpose of this search form is to filter by all those search boxes and return ONLY Building ID and Room ID. I have list boxes which populate data based on those two text boxes.
After much research, I've determined it must not be possible to filter out (filter out, not delete from table) duplicates in the form recordsource. It seems I am going to need to instead either clean up my query and/or use several smaller queries as my filter string instead of one super large one.
I've tried using several queries instead of one large one, but it would only use one of them as the filter string, not all of them. I need to figure out how to return building ID and room ID either using several different queries, or maybe by having different variables as Me.Filter =.
Another idea I had was to use different variables for Me.Filter and then use different queries. Ex.
But I do not imagine this to work.
I'm trying to create a search form which filters :
--Customers first name, last name, organization, shop name, office symbol
--Building Name, Room Name
--Equipment name, equipment serial number, equipment IP address
Each search box is a combo box. A user can filter by one combo box, or by several. So there is " AND " between each if statement.
At first I used a union query and set that query as the recordsource for the form. I needed it to be a union query due to the fact that customers could be a building POC or a room POC and I need to search through both. Also I need it to be an actual query (as opposed to a simple SQL statement in VBA code) because I need to use DCount to count records and tell the user if there are no results.
The problem w/ using one main query is that there are duplicate results in the form recordsourse. Like if Michael Smith, Andy Jones, and John Doe own BuildingFK 1, RoomsPK 10, if I filter by BuildingFK 1, RoomsPK 10 I will see 3 records.
Now, the purpose of this search form is to filter by all those search boxes and return ONLY Building ID and Room ID. I have list boxes which populate data based on those two text boxes.
After much research, I've determined it must not be possible to filter out (filter out, not delete from table) duplicates in the form recordsource. It seems I am going to need to instead either clean up my query and/or use several smaller queries as my filter string instead of one super large one.
I've tried using several queries instead of one large one, but it would only use one of them as the filter string, not all of them. I need to figure out how to return building ID and room ID either using several different queries, or maybe by having different variables as Me.Filter =.
Another idea I had was to use different variables for Me.Filter and then use different queries. Ex.
Code:
if cboSearchLastName is notNull then Me.Filter = strFilter1 else if cboSearchFirstName is notNull then Me.Filter = strFilter2 End If
Comment