Results 1 to 11 of 11
  1. #1
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95

    Help with rounding datetime

    Hi all,



    I'm messing this up somehow and can't get this right. I'm using Access 2010 and have a button on a form to add the current datetime and add 2 additional hours, which works fine.
    Me.DueTime = Now() + 2 / 24

    What I'm trying to add to this is to make it round to the near half hour.
    This is what I have tried, but getting a VBA error.
    RoundTime(Me.DueTime = Now() + 2 / 24, 1800)

    Any help would be great.
    Thanks,

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Presumably you got that here:

    http://allenbrowne.com/round.html

    Did you copy the function into a standard module in your db? Plus it would be:

    Me.DueTime = RoundTime(Now() + 2 / 24, 1800)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    Thanks for the reply. Yes, that is where I got it. I pasted this in, but still getting a compile error? Sorry, I'm pretty much a complete novice when it comes to Access and especially VBA.

    Private Sub Command118_Click()
    Me.DueTime = RoundTime(Now() + 2 / 24, 1800)
    End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    I could if I could figure out how do I add an attachment here?

  6. #6
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Can't you just use Access' builtin DateAdd() function?

    Code:
    Me!DueTime = DateAdd("hh", 2, Now())
    Edit: Oops, missed the last part of the question. Ignore this post!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    In the "Go Advanced" area there's a button to manage attachments. Compact/Repair, then zip and attach.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    Okay, I knocked the db down to only what was needed. It's the "add" button near the top right of the form.
    Attached Files Attached Files

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You didn't copy Allen's function into a standard module like I mentioned (Insert/Module in the VBA editor).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Delta729 is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Los Angeles
    Posts
    95
    Oh, I completely misunderstood that. I thought it was just that top section (formula part - I guess). Thanks for reviewing and clarifying, this worked perfectly; now.

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Get only date from a datetime in access
    By scorpion99 in forum Queries
    Replies: 4
    Last Post: 11-30-2013, 09:43 AM
  2. Dateserial and datetime
    By webisti in forum Access
    Replies: 1
    Last Post: 06-17-2013, 11:31 AM
  3. Convert text to datetime
    By kaledev in forum Queries
    Replies: 3
    Last Post: 01-28-2011, 10:21 AM
  4. How to build a datetime column ....
    By kkrishna in forum Access
    Replies: 3
    Last Post: 01-27-2011, 10:43 AM
  5. HELP with NULL DateTime VALUES
    By lfolger in forum Programming
    Replies: 3
    Last Post: 03-28-2008, 02:33 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