Results 1 to 8 of 8
  1. #1
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68

    Programatically add time to existing date

    I am having Access enter a "check-in" date based on a planned start date entered by user. The check-in date is 30 days after the planned start date and on different days of the week and at different times depending on the location of the check-in.

    This is on the before update event of a form. The function returns a Tuesday, which is correct, and the date returned is correct. I cannot figure out how to get the time in!

    If Me.Referring_Branch = "East" Then
    Me.CheckIn = dhSecondDayInWeek([Activity - Planned Start] + 30 ????????? - 3:00:00 PM
    End If



    Thanks for any help you can provide!

  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,770
    Concatenate.

    Me.CheckIn = dhSecondDayInWeek([Activity - Planned Start] + 30) & " 3:00:00 PM"

    Shouldn't need but if that has issue, maybe use date conversion function.

    Me.CheckIn = CDate(dhSecondDayInWeek([Activity - Planned Start] + 30) & " 3:00:00 PM")

    Advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    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
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    Thank you! Getting runtime error 13 with both of the above solutions......type mismatch. The format of the field 'checkin' is general date so I am not understanding why I am getting this error.

    And yes, the hyphen in my field names has caused me some trouble for sure! The data came out of Quickbase and Quickbase assigns that type of name to everything (Table Name - Field Name).

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The CheckIn field in table is a date/time type?
    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
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    Yes, the field in table is Date/Time with general date format

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Then I don't understand why the mismatch error.

    Debug your code. Use breakpoint and step through code - does the constructed date value really look like a date? Use Debug.Print.

    Otherwise, I would have to analyze your db.
    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
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    I am thinking it is a formatting issue, though I have tried every format trick I know. The Activity - Planned Start is 1/12/2016 1:30:00 PM, so the CheckIn date is coming out like this - 2/11/2016 1:30:00 PM 3:00:00 PM - which really isn't valid for the field and really IS a type mismatch. I have been trying to re-format the Activity -Planned Start to vbShortDate within the Before Update event procedure, but I am not having any luck.......

  8. #8
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    I figured it out......see below. Thank you for all your help June7!

    If Me.Referring_Branch = "East" Then
    Me.CheckIn = dhSecondDayInWeek(FormatDateTime(Forms!Form21!Form 3New.Form.[Activity - Planned Start] + 30, vbShortDate) & " 3:00:00 PM")
    End If

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

Similar Threads

  1. Replies: 11
    Last Post: 07-20-2014, 06:22 PM
  2. Subtracting a date/time field from a number to get date/time
    By Lifeseeker1019 in forum Programming
    Replies: 4
    Last Post: 03-28-2014, 12:59 PM
  3. Replies: 1
    Last Post: 03-13-2014, 07:23 PM
  4. Replies: 4
    Last Post: 03-06-2013, 02:32 PM
  5. Replies: 6
    Last Post: 01-04-2011, 05:43 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