?
Solved

Access count of all records with same value

Posted on 2013-06-06
1
Medium Priority
?
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

762 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