Compare Dates in VBA

Here’s how you can fix your code. Of course it’s not the best way to do date calculations, and you’ll also have to validate that there is text in the 2 text boxes, and maybe even use CDate() to parse the text to date values, but this will work for your current situation.

If DateDiff("d", txtOrderDate.Text, txtRecievedDate.Text) < 0 Then

   MsgBox "Incorrect Date, item can't be recieved before order"

else    

  MsgBox "correct date"

End If

Leave a Comment

tech