Solved

Access count of all records with same value

Posted on 2013-06-06
1
284 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

707 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

15 Experts available now in Live!

Get 1:1 Help Now