Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24

    DateAdd function not working

    In my form, i have three fields: Start Time, End Time and Duration.

    I try to calculate end time by add up start time and duration so i put DateAdd(n,Duration,StartTime) into the default value of end time. When i change the duration or starttime, the end time is not changed automatically.



    What I did wrong??..

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    the time interval parameter is a string:

    DateAdd("n",Duration,StartTime)

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Show readers the real code you are using.
    Review DateAdd
    Check the format and syntax carefully.

    Why do you need all three:
    StartTime, EndTime and Duration

  4. #4
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24
    The syntax is correct. I need start time and duration to calculate end time... Should i put the function into default value???..

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Show readers the code.


    Please tell us more about this?????
    Should i put the function into default value???

  6. #6
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24
    Click image for larger version. 

Name:	KES)763S62@[PI46TX[6BQB.png 
Views:	13 
Size:	22.3 KB 
ID:	24522Click image for larger version. 

Name:	03M3TIOIJXT_PJ6RQ8Y5%CJ.png 
Views:	12 
Size:	4.1 KB 
ID:	24523

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Are you working with EndTime or Finishing Time? Unclear.

    In my form, i have three fields: Start Time, End Time and Duration.
    If you have 3 fields in your table, you do not need all three. Do not store calculated fields/values.

    How about posting a copy of the database in zip format?

  8. #8
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24

    my database

    appointmenthelp.zip plz check my database

  9. #9
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24
    i posted plz check

  10. #10
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Some comments:
    -Every table should have a primary key. No PK on Booking or BookingHistory tables
    -You should adopt a naming convention that does NOT allow embedded spaces.
    -Date is a reserved word in Access.
    -Finishing Time in tblBooking
    -Finsihing Time in tblBookingHistory
    -tblTreatment does not have a Start nor End/Finishing Time ---only Duration.

    formBooking recordsource
    Code:
    SELECT tblBooking.[Booking ID], tblBooking.[Customer ID], tblBooking.[Therapist ID]
    , tblBooking.[Treatment ID], tblBooking.[Room ID]
    , tblBooking.Date, tblBooking.[Start Time], tblBooking.[Finishing Time], tblBooking.Completed
    , tblTreatment.Duration FROM tblTreatment INNER JOIN tblBooking 
    ON tblTreatment.[Treatment ID] = tblBooking.[Treatment ID];
    Attached Thumbnails Attached Thumbnails RecordsourceBookingForm.jpg   DurationStartFinishingTime.jpg  

  11. #11
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24
    Thank you so much. Can you explain why do i need start time and finishing time in tbltreatment? Also can you explain why dateadd function not working in the booking form.

  12. #12
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    ??
    Can you explain why do i need start time and finishing time in tbltreatment? I'm not saying you do. Your original post was about using DateAdd to determine/calculate a value. What you didn't tell us was that Starttime was in 1 table and Duration in another.

  13. #13
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24
    so you mean starttime and duration must be in the same table?

  14. #14
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Step back, forget your specific issue.

    If I said I have an appointment that starts at 12:15 today and lasts for 30 minutes. We're still talking about the same appointment, right? So they would typically be stored in the same table in database terms. The Duration is an attribute of this specific appointment.

  15. #15
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24
    ok. I understand what you said.

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

Similar Threads

  1. DateAdd not working
    By quinnsfpa in forum Forms
    Replies: 6
    Last Post: 11-10-2015, 01:06 AM
  2. used function DateAdd
    By azhar2006 in forum Queries
    Replies: 2
    Last Post: 10-07-2015, 03:31 PM
  3. DateAdd Function?
    By zburns in forum Reports
    Replies: 7
    Last Post: 06-23-2015, 01:55 PM
  4. DateAdd Function
    By jschlapi in forum Forms
    Replies: 4
    Last Post: 10-23-2013, 01:36 PM
  5. DateAdd Function
    By Desstro in forum Programming
    Replies: 3
    Last Post: 04-03-2011, 01:45 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