Date problem

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
I have a date textbox which is updated when another combobox is changed. When there no corresponding value for date, it automatically posts todays date in the date textbox.

Next to the date textbox I have a "X" which shows when the data is not valid. Here is the code for the date textbox

Code:
Private Sub txtDateOfAlert_Change()
txtTimeOfAlert.Value = ""
If Not txtDateOfAlert.Value Like "##[/]##[/]####" Then
  imgCross2.Visible = True
Else
    If IsDate(txtDateOfAlert) Then
        If CDate(txtDateOfAlert.Value) < CDate(txtDateOfAccident.Value) Or _
            (txtDateOfAlert.Value) > Format(Date, "dd/mm/yyyy") Then
                imgCross2.Visible = True
        Else
            imgCross2.Visible = False
        End If
    Else
        imgCross2.Visible = True
    End If
End If
'Specifies format of DateOfAlert
'Checks whether DateOfAlert value is a valid date
'Checks that DateOfAlert is after DateOfAccident and not in the future
'Defines Visibility
End Sub

The problem is the 'X' is still appearing initially when the date is shown in the textbox despite matching all the criteria. If I then click in the textbox, delete a character and then retype the same character the 'X' disappears.

Any idea why this isn't working. I have a similar thing for Time, which works fine.

If you need any further information, or I haven't been clear enough defining the problem then let me know
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,224,566
Messages
6,179,551
Members
452,927
Latest member
rows and columns

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top