MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Need some serious help!!!!!!!!


Posted by Andres on April 06, 2001 11:57 AM

Ok I'm making a program that finds the days and years
between two dates, the porblem is that, I want the person to type
the whole date like " 05/03/1985 " not " 05/03/85. If the person
writes down the last two digits of the years, I want to be able to
make a messasge box, saying " You must fill in the boxes correctly "
or something like that. Thats all. tnx for ur help

Andres :]


Posted by lenze on April 06, 2001 1:53 PM

Andres:

It doesn't matter how they enter the date, simply format the cells to display it the way you want it to be seen.

lenze

Posted by Andres on April 06, 2001 2:25 PM

Sorry I'm not following

I'm really sorry but I'm not following you Lenze.
I dont understand the Cell stuff.

Posted by lenze on April 06, 2001 2:27 PM

On Second Thought

On second thought, this is true assuming you are talking about current dates between 1930 and 2029. If outside this range, you may have to format your cells as text and then use data validation to limit the length to between 8 and 10 characters. You will then have to use the DateValue function to perform your calculations. I'm also sure someone can suggest a VBA code to require proper entry

lenze

Posted by Dave Hawley on April 06, 2001 8:59 PM

I'm assuming your talking about a UserForm with textboxes, if so try the code below. It requires a Userform, TextBox1, Textbox2 and CommandButton1

Option Explicit
Dim DateCheck2 As Date
Dim DateCheck1 As Date

Private Sub CommandButton1_Click()
MsgBox DateDiff("d", DateCheck2, DateCheck1)
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If Not IsDate(TextBox1) Then
MsgBox "Your date is not valid, please correct it.", vbCritical, "OzGrid Business Applications"
Cancel = True

Else
DateCheck1 = TextBox1.Value
TextBox1 = Format(TextBox1, "dd/mm/yyyy")

End If
End Sub


Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If Not IsDate(TextBox2) Then
MsgBox "Your date is not valid, please correct it.", vbCritical, "OzGrid Business Applications"
Cancel = True

Else
DateCheck2 = TextBox2.Value
TextBox2 = Format(TextBox2, "dd/mm/yyyy")

End If
End Sub


OzGrid Business Applications