Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    c918768 is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2025
    Posts
    4

    Testing a query

    I'm having trouble debugging a query that doesn't seem to be returning a correct result. I've simplified the query just to test it but when I click Run I don't see any information regarding whether it ran successfully. Can I run it from this window or does it need to executed in another manner? I attached a screen shot.
    Attached Thumbnails Attached Thumbnails Screenshot 2025-02-27 114702.png  

  2. #2
    Gustav's Avatar
    Gustav is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2025
    Posts
    32
    Try with: Select * From tblFTA_Final

  3. #3
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    open the query in design mode, click the SQL button and then post that here. Can't fix what we can't see.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    You need a FROM clause?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    Oh, stupid me. Forgot how to read. Yeah, a FROM clause helps a lot!! Sometimes JOINs are helpful too!

  6. #6
    c918768 is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2025
    Posts
    4
    I've gotten the query to run but I'm getting an error. Its trying to prevent division by zero but it looks like it might be testing non-numeric fields for 0. Can someone suggest what changes I should make?

    SELECT tblFTA_Final.*, IIf([Occurances]=0,0,IIf([Outages]=0,0,IIf([population]=0,0,IIf([MaterialFailures]=0,0,([Occurances]/[Outages])/([Population]/[MaterialFailures]))))) AS Expr1
    FROM tblFTA_Final;

    MaterialFailures Population Outages Occurances Computation Expr1
    0 369600 0 0 0
    1 369600 0 0 0
    0 369600 0 0 0
    0 369600 0 0 0
    0 369600 0 0 0
    0 369600 0 0 0
    0 369600 1 0 #Error
    0 369600 0 0 0
    0 369600 0 0 0
    0 369600 0 0 0
    0 369600 0 0 0
    0 369600 0 0 0

  7. #7
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    This is asking for trouble:
    ([Occurances]/[Outages])/([Population]/[MaterialFailures]))))) AS Expr1

    If [Outages], [Population] OR [MaterialFailures] is null, you'll get no answer. If any is zero, you'll get a division by zero error. One way to avoid that is to filter out any the records where any one of those is zero. You basically have to filter out any of those records to avoid the divide by zero error.

    SELECT *
    FROM <source object>
    WHERE [Outages] > 0
    AND [Population] > 0
    AND [Material Failures] > 0

    and then you'd base your totals query on that. Otherwise, you're going to generate DIV/0 errors.

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    IIf([Outages]=0,0

    Nor do any of those make sense. In English it says,' if outages is zero then use 0'. If you have to use something like that, why not use 1 as the value for when the expression is false? Then division by 1 won't change the value - 0/1 = 0. But I agree, better to eliminate those records if you can.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,205
    Hi @Gustav
    Good to see you here as well

    For the benefit of others, Gustav has been an Access MVP since around 2017 and is an expert. He is certainly NOT a novice which for some reason is purely based on post count at this forum!
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Quote Originally Posted by isladogs View Post
    Hi @Gustav
    Good to see you here as well

    For the benefit of others, Gustav has been an Access MVP since around 2017 and is an expert. He is certainly NOT a novice which for some reason is purely based on post count at this forum!
    Yes, and we have many 'Competent Performer's here, which are really not.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    I knew that long ago when I got bumped up from novice to VIP and thought "What?". It's arbitrary for sure, so I never go by the forum ranking when trying to assess anyone's level of competency in Access. I'm still a VIP of a sort though.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    437
    try:
    Code:
    SELECT tblFTA_Final.*, IIf([Outages]=0 Or [population]=0 Or [MaterialFailures]=0, 0,([Occurances]/[Outages])/([Population]/[MaterialFailures])) AS Expr1
    FROM tblFTA_Final;

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Or

    IIf(IsNull(Outages + Population + MaterialFailures), 0, ([Occurances]/[Outages])/([Population]/[MaterialFailures]))

    Or

    IIf(Outages + Population + MaterialFailures IS NULL, 0, ([Occurances]/[Outages])/([Population]/[MaterialFailures]))


    Side Note: correct spelling of Occurances would be Occurrences

    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.

  14. #14
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    437
    based on the Query string and the output on post #4, there is no Null values there.

  15. #15
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,880
    Quote Originally Posted by Micron View Post
    I knew that long ago when I got bumped up from novice to VIP and thought "What?". It's arbitrary for sure, so I never go by the forum ranking when trying to assess anyone's level of competency in Access. I'm still a VIP of a sort though.
    You've always been a VIP to those of us who've known you for years.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 03-04-2021, 04:01 AM
  2. testing query for results
    By Jen0dorf in forum Access
    Replies: 4
    Last Post: 08-29-2016, 08:49 PM
  3. Testing Task - Forms
    By collwill in forum Access
    Replies: 1
    Last Post: 03-09-2011, 10:25 PM
  4. Replies: 3
    Last Post: 11-08-2010, 11:09 AM
  5. Testing links
    By piflechien73 in forum Forms
    Replies: 0
    Last Post: 06-01-2009, 05:09 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