Results 1 to 9 of 9
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Total query with date/time fields

    I have a query showing booking times. We consider booking time a single "booking"

    There are up to 5 fields in the booking table - each is a date/time field (1PM show, 2 PM show etc)



    I need to add these together for totals however if I make a calculation in the query say expre1: 1stTime + 2ndTime it will obviously add the values - I want to count the columns if they are not null

    so if 1st and 2nd time are filled out on a record then that is 2 bookings for the show

    but if 1st time is filled only then just 1 booking.

  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Click image for larger version. 

Name:	Capture.jpg 
Views:	10 
Size:	24.2 KB 
ID:	13650

    Just to make it more clear, each field row has a total of "count" so that it ads the number of count for showTime1st, 2nd etc. But I want to show a column that adds those counted rows together in a sum

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Use IIf expression.

    IIf([CountOfTime1st]>0,1,0) + IIf([CountOfTime2nd]>0,1,0) + IIf([CountOfTime3rd]>0,1,0) + IIf([CountOfTime4th]>0,1,0) + IIf([CountOfTime5th]>0,1,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.

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Use IIf expression.

    IIf([CountOfTime1st]>0,1,0) + IIf([CountOfTime2nd]>0,1,0) + IIf([CountOfTime3rd]>0,1,0) + IIf([CountOfTime4th]>0,1,0) + IIf([CountOfTime5th]>0,1,0)
    CountOfTime1st and the rest don't exist. They are made from ShowofTime1st but then total "Count" in the query. So If I try to add, the query gives me a parameter question.

    I've got it working on the form, but the query doesn't work by itself.

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Click image for larger version. 

Name:	Capture.JPG 
Views:	7 
Size:	43.9 KB 
ID:	13663

    See here

    update also IIf([ShowTime1st]>0,1,0)+IIf([ShowTime2nd]>0,1,0)+IIf([ShowTime3rd]>0,1,0)+IIf([ShowTime4th]>0,1,0)+IIf([ShowTime5th]>0,1,0) just = 1 however if I count that I get 11...

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Sorry, I left 'Show' out of the field names. Try my suggested expression with the correct field names: CountOfShowTime1st, etc
    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
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Sorry, I left 'Show' out of the field names. Try my suggested expression with the correct field names: CountOfShowTime1st, etc
    Yeah I tried, it didn't work but I just used ShowTime1st and then added them (as seen above) and then just put them into count instead of groupby and it seems to work - will let you know if it breaks. I have to add some shows with different times to be sure - but I've detoured on another puzzle (correct syntax for open form multiple parameters).

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I changed to groupby for Expr1: IIf([ShowTime1st]>0,1,0)+IIf([ShowTime2nd]>0,1,0)+IIf([ShowTime3rd]>0,1,0)+IIf([ShowTime4th]>0,1,0)+IIf([ShowTime5th]>0,1,0) and it works

    Update- it's not counting ALL the shows on separate bookings...

    Click image for larger version. 

Name:	Capture.jpg 
Views:	7 
Size:	20.2 KB 
ID:	13664

    Ideally because there are two shows at time2nd and two shows at time1st for Australian Folklore there should be 4 shows in total.

    um heh... I changed it to sum instead of count and it works

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Click image for larger version. 

Name:	Capture.JPG 
Views:	9 
Size:	52.1 KB 
ID:	13665
    just so people can see..

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

Similar Threads

  1. Replies: 3
    Last Post: 06-18-2013, 08:17 PM
  2. Replies: 3
    Last Post: 06-01-2012, 03:24 AM
  3. Separating Date and Time into Two Input Fields
    By Chris1112 in forum Queries
    Replies: 8
    Last Post: 05-09-2012, 08:28 AM
  4. Two Date/Time and Memo Fields
    By Luke in forum Access
    Replies: 3
    Last Post: 08-24-2011, 02:55 PM
  5. problem in splitting Date and time fields
    By swaroop1012 in forum Queries
    Replies: 1
    Last Post: 11-22-2008, 11:29 AM

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