Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2006
    Posts
    157

    Unanswered: Logical Error in Accounts Distribution

    Hi: In the listbox name lstOpenAccounts there are three hundred values. In another listbox name lstseldist there are two values but it could be three or four. Assume from the first listbox name lstOpenAccounts I select 150 Accounts and in the second list box name lstseldist there are two name for accounts distribution. If its a 150 values in lstOpenAccounts then 75 each will be distribute to each name which are in lstseldist but the program gives 76 to one and 74 to another. Its total is 150 but the distribution is wrong. The Program goes to Case Else in function distributeByQuantity but it not distribute values correctly. Dont know what logic i use so that the accounts will be distributed correctly. NEEDS HELP



    Private Sub cmdAssignAccounts_Click()
    Dim multiUserDistCount As Integer

    Screen.MousePointer = vbHourglass
    Set AcctsToDist = Nothing
    If optEvenDollarDist.Value = True Then
    distributeByEvenDollar
    Else
    distributeByQuantity (multiUserDistCount)
    End If

    Screen.MousePointer = vbNormal

    'Calls frmUserReassign
    If lstOpenAccounts.SelCount > 0 Then
    frmUserReAssign.AcctCol = Nothing
    frmUserReAssign.AcctCol = AcctsToDist
    Set Criteria.AccountCollection = Nothing
    frmUserReAssign.Show vbModal
    lstOpenAccounts.Clear
    cmdSelectAll.Caption = "Select All"
    End If
    End Sub
    ---------------------------------------------------------------
    Public Function FindSelectedListBoxItems(LstBx As Control) As Collection
    Dim i As Long
    Dim colCollection As New Collection

    For i = (LstBx.ListCount - 1) To 0 Step -1
    If LstBx.Selected(i) Then
    colCollection.Add LstBx.List(i)
    End If
    Next
    Set FindSelectedListBoxItems = colCollection
    Set colCollection = Nothing 'New Collection
    End Function

    ---------------------------------------------------------------
    Private Sub distributeByQuantity(multiUserDistCount As Integer)
    Dim distributeTo As Collection, acctsToDistribute As Collection
    Dim i As Integer, c As Integer, x As Integer, j As Integer
    Dim account As String, targetAIdIndex As Integer

    'Calls function in modProcessingFunctions
    Set distributeTo = FindSelectedListBoxItems(lstDist)
    Set acctsToDistribute = FindSelectedListBoxItems(lstOpenAccounts)


    'Used to maintain correct user
    x = 1
    j = 1

    Set AcctsToDist = New Collection

    Select Case multiUserDistCount
    Case 0
    For i = 1 To acctsToDistribute.Count
    account = acctsToDistribute(i)
    targetAIdIndex = 0
    'get acct location in criteria.accountcollection
    Do While targetAIdIndex <= lstOpenAccounts.ListCount
    If lstOpenAccounts.List(targetAIdIndex) = account Then
    'set j = collection index
    j = targetAIdIndex + 1
    'exit while loop
    targetAIdIndex = lstOpenAccounts.ListCount
    End If
    targetAIdIndex = targetAIdIndex + 1
    Loop
    'save old assign_id and set new one

    Criteria.AccountCollection(j).Old_Assign_Id = Criteria.AccountCollection(j).Assign_ID
    Criteria.AccountCollection(j).Assign_ID = Trim(distributeTo(1))
    AcctsToDist.Add (Criteria.AccountCollection(j))
    Next
    Case Else
    'Used to verify each user receives the same amt
    c = 0
    'distribute each account


    For i = 1 To acctsToDistribute.Count
    'true when c = multiuserdistcount, goes to next user
    If multiUserDistCount = c - 1 Then
    c = 0
    x = x + 1
    End If
    account = acctsToDistribute(i)
    targetAIdIndex = 0
    'get acct location in criteria.accountcollection
    Do While targetAIdIndex < lstOpenAccounts.ListCount
    If lstOpenAccounts.List(targetAIdIndex) = account Then
    'set j = collection index
    j = targetAIdIndex + 1
    'exit while loop
    targetAIdIndex = lstOpenAccounts.ListCount
    End If
    targetAIdIndex = targetAIdIndex + 1
    Loop

    Criteria.AccountCollection(j).Old_Assign_Id = Criteria.AccountCollection(j).Assign_ID
    Criteria.AccountCollection(j).Assign_ID = Trim(distributeTo(x))

    AcctsToDist.Add Criteria.AccountCollection(j)
    'Adds account count to user
    c = c + 1
    Next
    End Select

  2. #2
    Join Date
    Jul 2006
    Posts
    157
    If lstDist.SelCount = 1 Then
    multiUserDistCount = 0
    'Multiple users acquiring accounts
    ElseIf lstDist.SelCount > 1 Then
    multiUserDistCount = lstOpenAccounts.SelCount / lstDist.SelCount
    ElseIf lstDist.SelCount = 0 Then
    MsgBox "You must select the users to receive accounts. "
    Exit Sub
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •