+ Reply to Thread
Results 1 to 4 of 4

Code works great until the last day of the month

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Code works great until the last day of the month

    I created the following coding to prevent days from being unintentionally skipped. It has worked fine until after the first entry of the last day of the month is reached, as I discovered today, in other words, after the 2am entry is made, the 4am entry can't be made. I realize that I'm comparing the current date value to itself plus 1, what I can't figure out is how to make it not skip the rest of the day. I hope I explained it well enough, I've also included an attachment to help if at all possible.

    If cboDate.Value > Format(DateAdd("d", 1, txtLDate.Value), "dd-mmm-yy") Then
        Me.cboDate.SetFocus
        MsgBox "Whoa there partner!!!" & vbLf & "Slow those horses down some!!!" & vbLf & _
        "The " & Format(DateAdd("d", 1, txtLDate.Value), "dd-mmm-yy") & " Thermals are missing" & vbLf & _
        "Enter them first cowboy.", vbExclamation, "Missing A Date"
      Exit Sub
    End If
    FixMe.xlsm

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Code works great until the last day of the month

    You would be able to use something like:
    If CDate(cboDate.Value & " " & cboTime.Value) > CDate(txtLDate.Value & " " & txtLTime.Value) + TimeSerial(2, 0, 0) Then
    except that your data logs show 30-Oct-13 00:00 as being after 30-Oct-13 22:00, whereas most people (and computers!) would regard 31-Oct-13 00:00 as being two hours after 30-Oct-13 22:00
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: Code works great until the last day of the month

    Unfortunately that doesn't work with what I've got romperstomper. Even altering it to 24 hours (instead of 2) gets my msgbox error and the following, you can still make the entry, but you can now skip dates, which I want to prevent. Any variation of our code doesn't appear to work as I intend.

    If CDate(cboDate.Value & " " & cboTime.Value) > CDate(txtLDate.Value & " " & txtLTime.Value) + DateSerial(0, 0, 1) Then
    The "time" system where I work was originally developed back in the 1970s and they've stuck with it on all documentation since then and so, unfortunately, it is what I must work with.
    Last edited by LoneWolf3574; 10-31-2013 at 12:47 PM.

  4. #4
    Forum Contributor
    Join Date
    09-14-2012
    Location
    Tucson, Arizona, USA
    MS-Off Ver
    Office 2010
    Posts
    105

    Re: Code works great until the last day of the month

    I figured it out, I needed to use the DateValue function to achieve my goal.

    If DateValue(cboDate.Value) > DateValue(txtLdate.Value) + 1 Then
    It's amazing what difference HOW something is written when the comprehension of each is identical
    Last edited by LoneWolf3574; 10-31-2013 at 02:41 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Addin works great in all files except the one I want it to work in
    By JM_Brazil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2015, 06:48 PM
  2. [SOLVED] Code works great...UNTIL i call it from another sheet- Why?
    By Ppessina in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-27-2013, 03:52 PM
  3. Macro works great in 2007 but not in older excel format
    By Tom R. in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-18-2013, 05:52 AM
  4. Replies: 0
    Last Post: 11-08-2012, 03:49 PM
  5. VBA Macro checks for duplicates,works great, but wish to add a select row
    By Mesjoggah in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-30-2011, 01:28 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1