Results 1 to 7 of 7

Thread: [RESOLVED] Check if DTPicker1 time value is incresed by 5 minutes from the current time

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [RESOLVED] Check if DTPicker1 time value is incresed by 5 minutes from the current time

    I have a time picker that sets reminders it opens to the current time. I want to make sure the time is increased by 5 minutes when the OK button is clicked
    if DTPicker1.value < 5 minutes from now
    msgbox "you must increase the time by at least 5 minutes"
    Exit Sub
    end if
    it opens like this:


    DTPicker1.CustomFormat = "hh:mm tt"
    DTPicker1.Format = dtpCustom
    DTPicker1.Value = Now
    DTPicker1.Format = 2
    it shows the time as AM/PM

    have tried this

    If DateDiff("n", Time, DTPicker1.Value) < 5 Then
    MsgBox "You must increase the time by at least 5 minutes."
    End If

    and this:
    Dim date1 As Date
    date1 = CDate(DTPicker1.Value)
    If DateDiff("n", date1, Now) < 5 Then
    MsgBox ("You must increase the time by at least 5 minutes.")
    End If

    they do not work

    how can this be written ?
    Name:  choose time.jpg
Views: 251
Size:  15.6 KB
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    Re: Check if DTPicker1 time value is incresed by 5 minutes from the current time

    Shouldn't it be "m" instead of "n" in DateDiff, to compare minutes?

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Check if DTPicker1 time value is incresed by 5 minutes from the current time

    Looks like you have the values reversed from what you want. If you want 5 minutes or more from now then you want

    Code:
    If DateDiff("n",Now,date1) < 5 Then
    The way you have it would give you 5 minutes or more before now rather than after

    If you want 5 minutes or more in either direction then you can use the ABS() function
    Code:
    If ABS(DateDiff("n",Now,date1)) < 5 Then

  4. #4

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Check if DTPicker1 time value is incresed by 5 minutes from the current time

    Quote Originally Posted by fafalone View Post
    Shouldn't it be "m" instead of "n" in DateDiff, to compare minutes?
    Thanks , but need to check total time, if hours are increased then it wold be more than 5 minutes
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Check if DTPicker1 time value is incresed by 5 minutes from the current time

    Quote Originally Posted by fafalone View Post
    Shouldn't it be "m" instead of "n" in DateDiff, to compare minutes?
    m is for Months n is used for minutes

    a bit confusing but.....

    anyway the values being in the wrong position is likely why he was having a problem

  6. #6

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Check if DTPicker1 time value is incresed by 5 minutes from the current time

    Quote Originally Posted by DataMiser View Post
    m is for Months n is used for minutes

    a bit confusing but.....

    anyway the values being in the wrong position is likely why he was having a problem
    This works

    If DateDiff("n", Time, TimeValue(DTPicker1.Value)) < 5 Then
    MsgBox "You must increase the time by at least 5 minutes."
    End If
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: [RESOLVED] Check if DTPicker1 time value is incresed by 5 minutes from the curren

    That is pretty much what i showed in my post, you have dropped the date part but the key is the order in which they appear in the statement

    Code:
    If DateDiff("n", now, DTPicker1.Value) < 5 Then
    Would give you the same result

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width