Results 1 to 7 of 7
  1. #1
    boomerang is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2011
    Posts
    16

    Code results in error on the first day of every month

    On the first day of every month, this code results in an error



    Code:
        ElseIf Me.txtReceiptDate & " " & Me.txtReceiptTime > Format(Now(), "dd/mm/yyyy hh:nn") = True Then
        
            MsgBox "Date out of range." & vbCrLf & vbCrLf & "'Receipt Date / Receipt Time' cannot be set in the future " & _
            "and must be less than the current date and time - " & Format(Now(), "dd/mm/yyyy hh:nn") & ".", vbInformation, "Information"
            Me.txtReceiptDate.SetFocus
    if I am inputting a date from the previous month.

    Would really appreciate help to patch the code.

    Thanks!

  2. #2
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Try this:
    ElseIf CDate(Format(Me.txtReceiptDate & " " & Me.txtReceiptTime, "dd/mm/yyy hh:nn")) > Format(Now(), "dd/mm/yyyy hh:nn") = True Then

  3. #3
    boomerang is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2011
    Posts
    16
    Type mismatch :-(

    But thanks!

  4. #4
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Quote Originally Posted by boomerang View Post
    Type mismatch :-(

    But thanks!
    Can you post the rest of your code? Also, what is the value of Me.txtReceiptDate and Me.txtReceiptTime?

  5. #5
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    How about this version??

    Code:
       ElseIf (Format(CDate(Me.txtReceiptDate & " " & Me.txtReceiptTime), "dd/mm/yyyy hh:nn") > Format(Now(), "dd/mm/yyyy hh:nn")) = True Then
    
          MsgBox "Date out of range." & vbCrLf & vbCrLf & "'Receipt Date / Receipt Time' cannot be set in the future " & _
                 "and must be less than the current date and time - " & Format(Now(), "dd/mm/yyyy hh:nn") & ".", vbInformation, "Information"
          Me.txtReceiptDate.SetFocus
       End If

  6. #6
    boomerang is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2011
    Posts
    16
    It doesn't throw up the type mis match but it does trigger the msgbox. It thinks the date is in the future for some reason. Thanks all.

  7. #7
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by boomerang View Post
    It doesn't throw up the type mis match but it does trigger the msgbox. It thinks the date is in the future for some reason. Thanks all.
    Is the code working correctly for you?

    I changed the regional settings on my computer to Englisk(British) to get the date to display mm/dd/yyyy. Then I created a form and added two text boxes and a button. After renaming the text boxes, I added this code to the On Click event:

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub Command4_Click()
       Dim RD As Date   'RD = Receipt Date
       Dim dtNow As Date  ' DN = Date Now
    
       RD = CDate(Me.txtReceiptDate & " " & Me.txtReceiptTime)
       dtNow = Format(Now(), "dd/mm/yyyy hh:nn")
    
       If True = False Then
          'so I could use the ElseIf
    
       ElseIf RD > dtNow Then
    
          MsgBox "Date out of range." & vbCrLf & vbCrLf & "'Receipt Date / Receipt Time' cannot be set in the future " & _
                 "and must be less than the current date and time - " & dtNow & ".", vbInformation, "Information"
          Me.txtReceiptDate.SetFocus
       Else
          MsgBox "Good Receipt Date / Receipt Time!"
       End If
    End Sub
    If I set the Receipt Date to tomorrow's date, I get the error message. When I set the Receipt Date to yesterday's date, I get the Good Date message.

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

Similar Threads

  1. Track capacity changes month by month
    By Nils in forum Database Design
    Replies: 1
    Last Post: 02-18-2011, 03:03 PM
  2. Replies: 5
    Last Post: 11-15-2010, 06:12 PM
  3. Error in Code
    By Lockrin in forum Programming
    Replies: 3
    Last Post: 02-25-2010, 03:27 PM
  4. Replies: 4
    Last Post: 01-11-2010, 11:41 PM
  5. Replies: 16
    Last Post: 09-23-2009, 08:47 AM

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