VBA noob Trouble with DateDiff in VBA application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • royale47
    New Member
    • Sep 2011
    • 2

    VBA noob Trouble with DateDiff in VBA application

    the following is not returning a negative number even when the start date is later than the end date. Some help would be very appreciated! thank you -


    Private Sub CommandButton1_ Click()
    If DateDiff("d", ConfigStartDate , ConfigEndDate) >= 0 Then
    Range("ConfigEn dDate").Value = Calendar1.Value
    UserForm3.Hide
    Else
    MsgBox "End Date is Before start date"
    End If
    End Sub
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    This is working:
    vb6 form with commandbutton and 2 textboxes

    Code:
    Private Sub Command1_Click()
    Dim ConfigStartDate As Date
    Dim ConfigEndDate As Date
       ConfigStartDate = Day(txtConfigStartDate.Text)
       ConfigEndDate = Day(txtConfigEndDate.Text)
       If DateDiff("d", ConfigStartDate, ConfigEndDate) >= 0 Then
          'Range("ConfigEndDate").Value = Calendar1.Value
          'UserForm3.Hide
          MsgBox "End Date is AFTER start date"
       Else
          MsgBox "End Date is Before start date"
       End If
    End Sub

    Comment

    • royale47
      New Member
      • Sep 2011
      • 2

      #3
      Thank you looking at your code I realized I needed to read the values for configstartdate and configenddate from the worksheet into a local variable before the operation, it works now.

      probabaly basic stuff but just getting into VBA.

      Comment

      Working...