[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Access count of all records with same value

Posted on 2013-06-06
1
Medium Priority
?
342 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

873 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