Results 1 to 13 of 13
  1. #1
    jtmott is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2013
    Posts
    17

    Query returns nothing

    Hello,
    I have a query that run on tables through ODBC off an AS400. The query sums information based on today's date. it works fine except first thing in the mornings before information for the current date has been entered at which time the query does not return any output. I have tried Null statements and if statements but I am receiving the same results. The goal is to return today's date with Earned labor = 0 when today's date is not present in the AS400 table.


    any help would be greatly appreciated.
    example in SQL view:
    SELECT CDate(Mid([BPCSF6_ITHL01!TTDTE],5,2) & "/" & Right([BPCSF6_ITHL01!TTDTE],2) & "/" & Left([BPCSF6_ITHL01!TTDTE],4)) AS [Date], Sum(BPCSF6_ITHL01!TQTY*ATCCST!LABCST)/0.57 AS [Earned Labor] INTO [Earned Labor Table]
    FROM (BPCSF6_ITHL01 LEFT JOIN BPCSF6_IIML01 ON BPCSF6_ITHL01.TPROD = BPCSF6_IIML01.IPROD) LEFT JOIN ATCCST ON BPCSF6_ITHL01.TPROD = ATCCST.PARTC
    WHERE (((BPCSF6_ITHL01.TPROD)<>"60148-A") AND ((BPCSF6_ITHL01.TTDTE)>=20150101) AND ((BPCSF6_ITHL01.TTYPE)="PR" Or (BPCSF6_ITHL01.TTYPE)="CI" Or (BPCSF6_ITHL01.TTYPE)="IC" Or (BPCSF6_ITHL01.TTYPE)="RD" Or (BPCSF6_ITHL01.TTYPE)="Y") AND ((BPCSF6_IIML01.IITYP)="1" Or (BPCSF6_IIML01.IITYP)="2") AND ((BPCSF6_ITHL01.TWHS)="TX") AND ((BPCSF6_IIML01.IPROD)<>"60149-A"))
    GROUP BY CDate(Mid([BPCSF6_ITHL01!TTDTE],5,2) & "/" & Right([BPCSF6_ITHL01!TTDTE],2) & "/" & Left([BPCSF6_ITHL01!TTDTE],4))
    HAVING (((CDate(Mid([BPCSF6_ITHL01!TTDTE],5,2) & "/" & Right([BPCSF6_ITHL01!TTDTE],2) & "/" & Left([BPCSF6_ITHL01!TTDTE],4)))=Date()));

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    Well, that's the way queries work. If there is no data then the query has no records and there is nothing for any calculations to work with.

    Why do you need to show 0 labor for current date in a query?

    I don't use dynamic parameters in queries. I apply filter criteria to form or report based on unfiltered query.
    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
    jtmott is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2013
    Posts
    17
    I use this query results to display on a HTML page for a status board along with other data collected.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    Suggest you have code that tests if there are records and if not, display text: "No data yet today."
    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.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,736
    The goal is to return today's date with Earned labor = 0 when today's date is not present in the AS400 table.
    any help would be greatly appreciated.
    If you know there are no records for today, why not just have a query to update [Earned Labor Table] with Today's date and 0 AS [Earned Labor].

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    Yes, a dummy record is an option.

    As Orange suggests, manually create record with 0 Labor and run UPDATE sql action to change the date every day.
    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.

  7. #7
    jtmott is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2013
    Posts
    17
    This query is part of a macro that is triggered to run every 5 min throughout the day. Is there perhaps code that would allow me to post results from another table when there is no results from this query?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    Probably. What code do you have now?

    But the dummy record would also accomplish what you want.
    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.

  9. #9
    jtmott is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2013
    Posts
    17
    This the VBA code I'm using.
    Dim db As Database
    Set db = CurrentDb
    Dim rs As Recordset
    Set rs = db.OpenRecordset("Select * from Status_Table where ID = 1")

    'Get the number to print/display:
    Dim LG As Variant
    LG = rs!Labor_Goal
    Dim EL As Variant
    EL = rs!Earned_Labor
    Dim LN As Variant
    LN = rs!Labor_Needed
    Dim AC As Variant
    AC = rs!Accidents
    Dim PG As Variant
    PG = rs!Packed_goal
    Dim PK As Variant
    PK = rs!Packed
    Dim PN As Variant
    PN = rs!Packed_Needed
    Dim PL As Variant
    PL = rs!Past_Lines
    Dim PT As Variant
    PT = rs!Past_Total
    rs.Close

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,736
    How about some logic
    Code:
    If  today'sRecordCount = 0 then
        update  [Earned Labor Table] with Today's date and 0 AS [Earned Labor]
    Else
        run your existing sql
    end if

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,736
    Quote Originally Posted by jtmott View Post
    This the VBA code I'm using.
    Dim db As Database
    Set db = CurrentDb
    Dim rs As Recordset
    Set rs = db.OpenRecordset("Select * from Status_Table where ID = 1")

    'Get the number to print/display:
    Dim LG As Variant
    LG = rs!Labor_Goal
    Dim EL As Variant
    EL = rs!Earned_Labor
    Dim LN As Variant
    LN = rs!Labor_Needed
    Dim AC As Variant
    AC = rs!Accidents
    Dim PG As Variant
    PG = rs!Packed_goal
    Dim PK As Variant
    PK = rs!Packed
    Dim PN As Variant
    PN = rs!Packed_Needed
    Dim PL As Variant
    PL = rs!Past_Lines
    Dim PT As Variant
    PT = rs!Past_Total
    rs.Close
    And what do you do with this???

  12. #12
    jtmott is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2013
    Posts
    17
    Setting up a dummy record combined with using EOF statements in my VBA code did the trick.
    Thanks for pointing me in the right direction.

  13. #13
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,736

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

Similar Threads

  1. SELECT TOP 10 Query returns 12 records
    By Paul H in forum Queries
    Replies: 8
    Last Post: 09-11-2013, 03:38 PM
  2. Query returns ro results
    By MichealShinn in forum Queries
    Replies: 5
    Last Post: 02-21-2012, 01:24 PM
  3. CrossTab Query Max X Returns
    By systems013 in forum Access
    Replies: 5
    Last Post: 11-04-2011, 01:12 PM
  4. Access Update Query returns -1
    By Chris Morag in forum Queries
    Replies: 2
    Last Post: 05-27-2011, 06:02 AM
  5. Query returns duplicates
    By RobRay in forum Queries
    Replies: 3
    Last Post: 10-26-2010, 01:38 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