我希望在这个文本框里,只能输入090930(两位年+两位月+两位日)这种格式的日期。
如果输入的内容不符合就会给出错误提示。我现在已经做了限制,文本框里只可以输入数字,其它的都输入不进去了。
If Chr(KeyAscii) Like "[!0-9]" Then
If KeyAscii <> 8 And KeyAscii <> 9 And KeyAscii <> 13 Then
KeyAscii = 0
End If
End If
但是我还需要怎么做,才能保证输入的格式是“090930”这样呢?
如果输入的内容不符合就会给出错误提示。我现在已经做了限制,文本框里只可以输入数字,其它的都输入不进去了。
If Chr(KeyAscii) Like "[!0-9]" Then
If KeyAscii <> 8 And KeyAscii <> 9 And KeyAscii <> 13 Then
KeyAscii = 0
End If
End If
但是我还需要怎么做,才能保证输入的格式是“090930”这样呢?
Dim sDate As String
sDate = Text1.Text
If Len(sDate) <> 6 Then Cancel = True: Exit Sub
Cancel = Not IsDate(Left(sDate, 2) & "/" & Mid(sDate, 3, 2) & "/" & Right(sDate, 2))
End Sub
PrivateSub
Text1_Validate(CancelAsBoolean)Dim
sDate As String
sDate= Text1.TextIfLen(sDate)<>6Then Cancel=True:ExitSub
Cancel=NotIsDate(Left(sDate,2)&"/"&Mid(sDate,3,2)&"/"&Right(sDate,2))
End Sub