I am trying to figure out how to make a message box display for a date if it is earlier than another date. These are for "Arrival" and "Departure" dates so I would like a message box to show if the departure date is before the arrival date (think that I'm hosting people, not sending them off :)). The dates are in text boxes on a user form. I only have a little bit of experience with VBA but I really enjoy using the program so I appreciate any help I can get!
I've tried this code:
[VBA]Option Explicit Private Sub CmdBtn_Add_Click() Dim DateDepart As Date Dim DateArrive As Date DateDepart = Txt_Depart.value DateArrive = Txt_Arrive.value If DateDepart.value < DateArrive.value Then MsgBox "Departure date is before arrival date", vbCritical, "Incompatible Departure Date" Exit Sub End If End Sub[/VBA]
but I keep getting "Compile Error: Variable not defined."
I created a practice user form where I can get the following to work:
[VBA]Option Explicit Private Sub CommandButton1_Click() If TextBox1.value > TextBox2.value Then MsgBox "Number is bigger!" End If End Sub[/VBA]
which works fine regardless of whether it is in a date format or not.