Hi Peeps,

I have wrote a function which validates a masked exit box date format. I have entered into the Mask property 00/00/0000 which on screen translates to __/__/____, great. If I get an invalid date I want to clear the content and reset the focus back giving a message box warning. Here is my code :-

Code:
        If mskControl.Text.ToString = "" Or mskControl.Text.ToString = sFormat.ToString Then
            sCheckDate = sFormat
            Exit Function
        End If

        If Not IsDate(mskControl.Text.ToString) Then
            Beep()
            MessageBox.Show("Invalid date format.", "Validate Date Format", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
            sCheckDate = sFormat.ToString            
            mskControl.Focus()
        Else
            sCheckDate = sFormatDate(mskControl.Text.ToString, "dd/MM/yyyy")
        End If
I should explain that I assign the returned value of this function to the control, i.e. maskedit.text = scheckdate(mskcontrol," / /")

It all seems to work until I then try to enter a new date. The first number a press seems to push the mask characters to the right and then the rest works. So if I entered 01/01/2009 I end up with _1/01/2009.

Any ideas please as I thought this would be no time at all to do.

Thanks,

Jiggy!