稍微加些代码就可以了(用了错误检测机制)。
If Text1.Text Like "????-??-??" Then
'已经按照这样的格式写了,再来检测是否为数字
Dim strY As String, strM As String, strD As String, strTemp As String
strY = Left(Text1.Text, 4)
strM = Mid(Text1.Text, 6, 2)
strD = Right(Text1.Text, 2)
strTemp = Format(strY & strM & strD, "0000-00-00")
On Error GoTo Err
If CDate(DateSerial(CInt(strY), CInt(strM), CInt(strD))) = strTemp Then
MsgBox "文字输入正确!", vbInformation
Else
Err:
MsgBox "输入的不是数字或日期格式错误!", vbExclamation
End If
Else
MsgBox "没有按照 ****-**-** 的格式写!", vbExclamation
End If
[此贴子已经被作者于2006-1-21 15:42:06编辑过]