Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9210615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:07:11+00:00 2026-06-18T01:07:11+00:00

I have a MS Access database with a list of transactions. I am trying

  • 0

I have a MS Access database with a list of transactions. I am trying to update a “Match” field on both records where they have some of the same values in fields (Document Number, Voucher Number, Subhead) but opposite amounts. It also needs to avoid duplicates.

    Document Number     Amount   ABS     Match
    N6809561990112      438.48   438.48
    N6809561990112      438.48   438.48
    N6809561990112     -438.48   438.48

What I the end result after the SQL should look like

    Document Number     Amount   ABS     Match
    N6809561990112      438.48   438.48   Y
    N6809561990112      438.48   438.48
    N6809561990112     -438.48   438.48   Y

The table name is “tblUnmatched”

I tried the following but it updated every record in the table to “Y”

strSql = "Update tblUnmatched SET match = 'Y' WHERE EXISTS(select * " & _
        "from tblUnmatched t1 " & _
        "inner join tblUnmatched t2 on " & _
        "t1.[DOCUMENT NUMBER] = t2.[DOCUMENT NUMBER]" & _
        "where t1.ABS = t2.ABS AND t1.AMOUNT <> t2.AMOUNT AND t1.SUBH = t2.SUBH)"
DoCmd.RunSQL strSql

I also tried this but it couldn’t handle the duplicate problem.

strSql = "Update tblUnmatched SET match = 'Y' WHERE [DOCUMENT NUMBER] IN(select t1.[DOCUMENT NUMBER] " & _
        "from tblUnmatched t1 " & _
        "inner join tblUnmatched t2 on " & _
        "t1.[DOCUMENT NUMBER] = t2.[DOCUMENT NUMBER]" & _
        "where t1.ABS = t2.ABS AND t1.AMOUNT <> t2.AMOUNT AND t1.SUBH = t2.SUBH)"
    DoCmd.RunSQL strSql
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:07:12+00:00Added an answer on June 18, 2026 at 1:07 am

    Your task is impractical in Access SQL without a primary key field. Although there is no such key in the data source you import, that does not prohibit you from adding one in Access.

    Add an autonumber primary key, id, to tblUnmatched. Then for each new batch of incoming data:

    1. import into a scratch table, tblScratch
    2. DELETE FROM tblUnmatched
    3. append the rows from tblScratch into tblUnmatched

    (The process could be cleaner if you can use SELECT FROM <your data source> to append directly to tblUnmatched, instead of first importing to tblScratch.)

    Save the following SELECT statement as qryFindMatches:

    SELECT
        sub.[Document Number],
        sub.Amount,
        sub.MinOfid,
        DCount(
            "*",
            "tblUnmatched",
            "[Document Number]='" & [Document Number]
                & "' AND Amount = -1 * " & [Amount]
            ) AS match_count
    FROM
        (
            SELECT [Document Number], Amount, Min(id) AS MinOfid
            FROM tblUnmatched
            GROUP BY [Document Number], Amount
        ) AS sub;
    

    Then the UPDATE you want can be fairly easy to create. Beware the performance may not be blazing fast; hopefully you can accommodate it once a month.

    UPDATE tblUnmatched
    SET [Match] = True
    WHERE id In
        (
            SELECT MinOfId
            FROM qryFindMatches
            WHERE match_count > 0
        );
    

    I added an additional row to your sample data and tested with Access 2007. I think this is what you want …

    id Document Number Amount   Match
     1 N6809561990112   $438.48 True
     2 N6809561990112   $438.48 False
     3 N6809561990112 ($438.48) True
     4 N6809561990112     $5.00 False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application i have a access database with a list of customers, this
I am in the process of rewriting an Access database and I have some
I am trying to produce a list of user that have access to particular
I'm using an Access Database that is designed relationally. I have a list of
I have a Microsoft Access database query that I'm trying to import into a
I have a loop on page to update an access database that takes 15-20
I have an access database with these tables: - sequences: it describes the sequences
I have an Access database (in Access 2003) with several tables, and data must
I have an Access database of 4M rows, each representing an individual customer order.
I have a Microsoft Access Database with an interface for usability ... But now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.