I have a query to find duplicate values in one of my tables. I open a recordset on this query and I want to compare groups that have multiple records.
The reason a group would have multiple records is that it is shifting to a new product. Each group has a group number, product, and membership values for 12 months. So I could have group 12345 with product AB123 and membership values for the first 6 months, then on the next line in my query I would have group 12345 with Product XY789 and membership in the last 6 months. In this case, I have a field in my original table that says, EndProduct, and in the record where the product is AB123, I put XY789 in the EndProduct so I know that group is moving to that product.
So what I want to try and do in the recordset is go through each group in the query, find all the rows that are for the same group, and look at the last month of membership. If one has data and one doesn't, I want to put the Product for the row that has data into the EndProduct field on the row that doesn't have data in the last month of membership. I'm pretty sure I can figure all that stuff out, what I don't know how to do in the recordset is how to look at data from both groups at the same time to compare them.
Would I need sometime like...(I'm not bothering with declarations)
I can already see a problem. When I set rst.Fields("EndProduct") it doesn't know which record to put it in. How do I tell it the right one?
Also, I know there would need to be rst.Edit and rst.Update in there but I'll do that when I get the logic figured out.
The reason a group would have multiple records is that it is shifting to a new product. Each group has a group number, product, and membership values for 12 months. So I could have group 12345 with product AB123 and membership values for the first 6 months, then on the next line in my query I would have group 12345 with Product XY789 and membership in the last 6 months. In this case, I have a field in my original table that says, EndProduct, and in the record where the product is AB123, I put XY789 in the EndProduct so I know that group is moving to that product.
So what I want to try and do in the recordset is go through each group in the query, find all the rows that are for the same group, and look at the last month of membership. If one has data and one doesn't, I want to put the Product for the row that has data into the EndProduct field on the row that doesn't have data in the last month of membership. I'm pretty sure I can figure all that stuff out, what I don't know how to do in the recordset is how to look at data from both groups at the same time to compare them.
Would I need sometime like...(I'm not bothering with declarations)
Code:
For a=0 to totalRows
GroupNumber = rst.Fields("GroupNumber")
Product1 = rst.fields("Product")
LastMonthMbrship = rst.Fields("DecMbrs")
Find matching group by the group number
LastMonthMbrship2 = new group's DecMbrs
Product2 = new group's product
If(LastMonthMbrsip > 0 AND LastMonthMbrship2 = 0) Then
rst.fields("EndProduct") = Product1
ElseIf (LastMonthMbrship2 > 0 AND LastMonthMbrship = 0) Then
rst.Fields("EndProduct") = Product2
I can already see a problem. When I set rst.Fields("EndProduct") it doesn't know which record to put it in. How do I tell it the right one?
Also, I know there would need to be rst.Edit and rst.Update in there but I'll do that when I get the logic figured out.