Link to home
Start Free TrialLog in
Avatar of CaptainGiblets
CaptainGibletsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access count of all records with same value

At the moment i have built the code below that does a dlookup from a table and displays the results in text boxes. When it does the lookup there will only ever be 1 record in the table it is searching, however i now need to expand it to find another value that could have say 10 records in it and adds all the values together and displays them in the same text boxes.

To try and make it a bit clearer i have attached a screenshot. So at the moment i the MID number will always be populated, and when the press a button it uses the mid to find the company ID and how many related mids there are, and then it goes and finds all the information for just that mid. I want to add a second button that will then do the same for the Company ID, however there could be loads of records instead of just one.


Dim columnNames, TextBox, Months As Variant
Dim M, C, T, X, Z As Integer
columnNames = Array("Sum Of CR", "Sum of CR TXNS", "Sum of DR", "Sum of DR TXNS", "Sum of MSC", "Sum of MMSC", "Sum of Auth")
TextBox = Array("txt_estate_creditsum_", "txt_estate_credittran_", "txt_estate_debitsum_", "txt_estate_debittran_", "txt_estate_msc_", "txt_estate_mmsc_", "txt_estate_auth_")
Months = Array("OCT 12", "NOV 12", "DEC 12", "JAN 13", "FEB 13", "MAR 13", "APR 13")
Dim item As Variant
'Dim totals As String
Dim grandtotal, totals As Currency
M = 1
C = 1
T = 1
grandtotal = 0
Do While Not M = 8
        X = 1
        T = 0
        'For Each item In TextBox
        totals = 0
        Do While Not T = 7
            Me(TextBox(T) & (M)).Value = DLookup("[" & columnNames(T) & " " & Months(M - 1) & "]", "tbl_EstateReview", ("[MID] = '" & Me.txt_estate_mid & "'"))
            If T = "4" Or T = "5" Or T = "6" Then
            totals = totals + Me(TextBox(T) & (M)).Value
            End If
            T = T + 1
        Loop
        
        Me("txt_estate_totals_" & (M)).Value = totals
        grandtotal = grandtotal + totals
X = X + 1
M = M + 1
    Loop

T = 0
Me.txt_estate_grandtotal.Value = grandtotal
Do While Not T = 7
    M = 1
    X = 0
    totals = 0
    Do While Not M = 8
        totals = totals + Me(TextBox(T) & (M)).Value
        M = M + 1
        X = X + 1
    Loop
    '
    '
    Me("txt_estate_totals1_" & (T + 1)).Value = totals
    T = T + 1
Loop

Open in new window

Untitled.png
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial