Solved

Access count of all records with same value

Posted on 2013-06-06
1
297 Views
Last Modified: 2013-06-13
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
0
Comment
Question by:CaptainGiblets
1 Comment
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39225007
Have you tried using DSum instead of DLookup?

DSum will give you the same information you are currently seeing if there is only on record corresponding to a given MID, but give you a total if there are multiple records.

(And if you need a count of the records per MID, use DCount)

The syntax of these functions follows the same rules as DLookup.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now