Results 1 to 6 of 6
  1. #1
    shindb81 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    10

    Recognizing non-record as zero


    I have a small clinic database with two tables, tblAppointments and tblPayments, which I would like to use for the query, qryBalance.
    So one tblAppointments record can contain several tblPayments records, as patients can make several small payments for one visit. I set up the query to show the amount charged from tblAppointments and the sum of payments made for that particular appointment from tblPayments, and finally, the difference in a new column. So the query contains the following fields:

    ApptID ApptDate AmountCharged SumofPaymtMade RemainingBalance

    It works, but only when there is at least one tblPayments record existing for any given appointment. If there is no payment record, the appointment record doesn't even show, when I want it to return the amount charged as the balance.

    I'm currently working around it by adding a payment record with 0 payment for all appointments without a payment, but I couldn't help but think there must be a better design.
    Can I make Access recognize non-record as zero?

    Thanks.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,649
    Does the query use INNER JOIN? Use LEFT or RIGHT JOIN - "Include all records from tblAppointments and only those from tblPayments that match"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    You need an OUTER JOIN. (to show whats missing in 1 table)
    in the Qry, dbl-click the line joining the 2 tables.
    select 2, or 3 depending on what you want to see ALL of...(the apptmts)
    save, run.

  4. #4
    shindb81 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    10
    Thank you to the above two!
    That has actually solved that part of the problem.
    The next step is to show only those appointments with a remaining balance. I made a new query, since it didn't seem like I could use a PaymtMadeOfSum in the same query as a variable for a calculated field.
    So anyway, in the new query, I add a new field, "RemainingBalance: [AmountCharged]-[PaymtMadeOfSum]", which works fine, until I put a criteria of ">0".
    At this time, I don't see the appointments with no payment made.

    In fact, even in the first query, if I put the criteria of ">0" on the PaymtMadeOfSum, appointments without payments don't show because there is no record of payment.
    How can I work around this?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,649
    I expect the issue is because the appointments without payments have Null in the payments field in the query so the Sum of payments for those appointments is a Null.

    Any arithmetic with Null results in Null. So handle possible Null.

    RemainingBalance: [AmountCharged]-Nz([PaymtMadeOfSum],0)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    shindb81 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    10
    That did the trick!
    Thank you

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 12-05-2011, 05:35 AM
  2. Database Recognizing VBA Change to Form
    By orcinus in forum Programming
    Replies: 2
    Last Post: 10-28-2011, 01:18 PM
  3. Macro not recognizing text box value
    By avarusbrightfyre in forum Access
    Replies: 1
    Last Post: 09-17-2011, 01:45 PM
  4. DLookup not recognizing valid record/type mismatch
    By walter189 in forum Programming
    Replies: 3
    Last Post: 07-21-2011, 07:03 AM
  5. Issue recognizing Excel 'ranges'
    By Captain Database ...!! in forum Import/Export Data
    Replies: 4
    Last Post: 07-18-2011, 02:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums