I have a combobox on a Form, which is being populated by a UNION query:
As you can see by the UNION query, both queries are looking at the same table (T_MaintenanceType). To distinqish the queries, I have added 'Item ' and 'Group ' to the "MaintenanceDescription". The query works, it shows me the result of both queries.
The result is, for example:
Group APK
Group KOMO
Item APK
But! If I select "Item APK" from the combobox, the combobox shows "Group APK"! My guess is that the combobox is using the "MaintenanceTypeID" internaly and is returning the first match it finds. As "Item APK" is truely "APK", the combobox just shows the first "APK" it finds: "Group APK".
How can I prevent this? How can I get the combobox to show "Item APK" when I select it?
Code:
sSQL = "SELECT [T_MaintenanceType].[MaintenanceTypeID], 'Item ' & [T_MaintenanceType].[MaintenanceTypeDescription] " & _
"FROM T_MaintenanceType " & _
"INNER JOIN " & _
"T_RequiredMaintenance ON T_MaintenanceType.MaintenanceTypeID = T_RequiredMaintenance.MaintenanceTypeID " & _
"WHERE [T_RequiredMaintenance].[AssetID] = " & iAssetID & " " & _
"ORDER BY 2 " & _
"UNION ALL " & _
"SELECT [T_MaintenanceType].[MaintenanceTypeID], 'Group ' & [T_MaintenanceType].[MaintenanceTypeDescription] " & _
"FROM T_MaintenanceType " & _
"INNER JOIN " & _
"(T_RequiredMaintenanceG INNER JOIN T_Assets ON T_RequiredMaintenanceG.AssetGroupID = T_Assets.AssetGroupID) " & _
"ON T_MaintenanceType.MaintenanceTypeID = T_RequiredMaintenanceG.MaintenanceTypeID " & _
"WHERE [T_Assets].[AssetID] = " & iAssetID & " " & _
"ORDER BY 2"
As you can see by the UNION query, both queries are looking at the same table (T_MaintenanceType). To distinqish the queries, I have added 'Item ' and 'Group ' to the "MaintenanceDescription". The query works, it shows me the result of both queries.
The result is, for example:
Group APK
Group KOMO
Item APK
But! If I select "Item APK" from the combobox, the combobox shows "Group APK"! My guess is that the combobox is using the "MaintenanceTypeID" internaly and is returning the first match it finds. As "Item APK" is truely "APK", the combobox just shows the first "APK" it finds: "Group APK".
How can I prevent this? How can I get the combobox to show "Item APK" when I select it?