I need your help with below code. I must check all dates in MSHFlexgrid1 col (1) to see if the date is a real date with format "MM/DD/YYYY"
If the date don't exist, it will put in Col(0) the note: "BAD DATE FORMAT".
If it says in Col(1): 01/15/2017, January 15 2017 is a date that exist, so not problem.
If it says in Col(1): 15/01/2015, this is a bad date as there is no Month 15.
So far, i have this code:
Private Sub val_date_exist_Click()
Dim strDate As String
Dim dt As Date
Dim I As Long
For I = 1 To MSHFlexGrid1.Rows - 1
strDate = Trim(MSHFlexGrid1.TextMatrix(I, 1))
dt = DateSerial(CInt(Mid(strDate, 1, 2)), CInt(Mid(strDate, 4, 2)), CInt(Mid(strDate, 7, 4)))
If strDate = Format(dt, "MM/DD/YYYY") Then
MSHFlexGrid1.TextMatrix(I, 0) = MSHFlexGrid1.TextMatrix(I, 1) & " - " & "BAD DATE FORMAT"
'Auto column fit
Dim c As Long
Dim cell_wid As Single
Dim col_wid As Single
Dim z As Long
For c = 0 To MSHFlexGrid1.Cols - 1
col_wid = 0
For z = 0 To MSHFlexGrid1.Rows - 1
cell_wid = TextWidth(MSHFlexGrid1.TextMatrix(z, c))
If col_wid < cell_wid Then col_wid = cell_wid
MSHFlexGrid1.ColWidth(c) = col_wid + 120
But it always tell me that the date is bad even if it as the good format.
I must be missing something in the code.
Hope you will be able to help.