ECEstudent
Registered User.
- Local time
- Today, 09:50
- Joined
- Jun 12, 2013
- Messages
- 153
Hi, I'm really stuck on this. Been looking at it for a few days now (even though I'm sure it's not that hard of a problem) and I would appreciate any help!
Here is my code:
So what's going on is that I'm first taking all the 'RepID' associated with some code from above (not important) and put them in an array...then I'm looping through that array and really only trying to find all the 'RepIds' that exist in table 'tbl_LBP_Sales Location Num', I should then start collecting all the order numbers and Items associated with those 'RepIds''. I understand I could have just collected all of those variables from the very beginning since they're using the same table but I am ONLY interested in the ones associated with the RepIds' that exist in table 'tbl_LBP_Sales Location Num'. And the code that comes after this step isn't important for this step.
My problem is that I have 2 things to count: 1) the number of RepIds' found in that table (and I'm calling that total 'VldOrdrNbrDestination') and 2) the OrderNumber + Item + RepId combination
Please notice that with SELECT DISTINCT at the top, I am getting the wrong RepId total and with out SELECT DISTINCT, I am getting the wrong combination total.
Please help. Thanks.
Here is my code:
Code:
Set rstt = CurrentDb.OpenRecordset( _
"Select Distinct RepId from CalculateTotal where ([Structure] like '*" & u & "*') Group By OrderNumber, Item, RepId", dbOpenDynaset, dbSeeChanges)
n = 0
While rstt.EOF = False
ReDim Preserve Arry(n)
Arry(n) = rstt.Fields("RepId") 'Store RepIds in array
n = n + 1
rstt.MoveNext
Wend
y = Arry
' VldOrdrNbrDestination = 0
' OrderWOEditing = 0
For Each varCod In y 'For each RepId in array
If DCount("[Location ID]", "[tbl_LBP_Sales Location Num]", "[Location ID] LIKE '*" & Left(varCod, 3) & "*' AND NOT [Rep Region Code] = 'INT' AND NOT [Rep Region Code] = 'inte'") > 0 Then 'Only count RepIds that exist in table 'tbl_LBP_Sales Location Num' and is not an international order
VldOrdrNbrDestination = VldOrdrNbrDestination + 1 'Calculate total number of orders
' MsgBox " Rep = '" & varCod & "'"
' MsgBox "Structure = '" & u & "'"
Set ry = CurrentDb.OpenRecordset( _
"SELECT OrderNumber, Item, RepId from CalculateTotal where ([RepId] = '" & varCod & "') AND ([Structure] like '*" & u & "*')", dbOpenDynaset, dbSeeChanges)
While ry.EOF = False
ReDim Preserve Arrk(e)
ReDim Preserve Arra(e)
ReDim Preserve ArrRep(e)
Arrk(e) = ry.Fields("OrderNumber") 'Collect its order numbers
Arra(e) = ry.Fields("Item")
ArrRep(e) = ry.Fields("RepId")
e = e + 1
ry.MoveNext
Wend
q = Arrk
v = Arra
End If
Next varCod ' next RepId
So what's going on is that I'm first taking all the 'RepID' associated with some code from above (not important) and put them in an array...then I'm looping through that array and really only trying to find all the 'RepIds' that exist in table 'tbl_LBP_Sales Location Num', I should then start collecting all the order numbers and Items associated with those 'RepIds''. I understand I could have just collected all of those variables from the very beginning since they're using the same table but I am ONLY interested in the ones associated with the RepIds' that exist in table 'tbl_LBP_Sales Location Num'. And the code that comes after this step isn't important for this step.
My problem is that I have 2 things to count: 1) the number of RepIds' found in that table (and I'm calling that total 'VldOrdrNbrDestination') and 2) the OrderNumber + Item + RepId combination
Please notice that with SELECT DISTINCT at the top, I am getting the wrong RepId total and with out SELECT DISTINCT, I am getting the wrong combination total.
Please help. Thanks.