综合 yinyb36 和 gryy 狐友的方法
达到了较为完美的日子输入
在ValidateEdit
输入代码:目的检测辅助输入列的键入格式是否等同日子的格式
If e.Col.Name = "S手雕S" Or e.Col.Name = "S手雕F" Or e.Col.Name = "S电雕S" Or e.Col.Name = "S电雕F" Then
Dim txt As String = e.Text
Dim mt1 As String = Mid(txt,1,2 )
Dim mt2 As String = Mid(txt,3,2 )
Dim mt3 As String = Mid(txt,5,2 )
Dim mt4 As String = Mid(txt,4,2 )
If txt.Length = 4 Then
If (( mt1 = "01" Or mt1 = "03" Or mt1 = "05" Or mt1 = "07" Or mt1 = "08" Or mt1 = "10" Or mt1 = "12" ) And mt2 <= "31" ) Or _
(( mt1 = "04" Or mt1 = "06" Or mt1 = "09" Or mt1 = "11" ) And mt2 <= "30" ) Or ( mt1 = "02" And mt2 <= "28" ) Then
e.Text = Date.Today.Year & "-" & Mid(txt,1,2) & "-" & Mid(txt,3,2)
Else
MessageBox.Show( "你输入的日子格式出錯!请以4位数字(月日)或6位数字(年月日),重新输入!")
e.Cancel = True
End If
ElseIf txt.Length = 6 Then
If (( mt2 = "01" Or mt2 = "03" Or mt2 = "05" Or mt2 = "07" Or mt2 = "08" Or mt2 = "10" Or mt2 = "12" ) And mt3 <= "31" ) Or _
(( mt2 = "04" Or mt2 = "06" Or mt2 = "09" Or mt2 = "11" ) And mt3 <= "30" ) Or ( mt2 = "02" And mt3 <= "28" ) Then
e.Text = "20" & Mid(txt,1,2 ) & "-" & Mid(txt,3,2) & "-" & Mid(txt,5,2)
Else
MessageBox.Show( "你输入的日子格式出錯!请以4位数字(月日)或6位数字(年月日),重新输入!")
e.Cancel = True
End If
ElseIf txt.Length = 5 Then
If (( mt1 = "01" Or mt1 = "03" Or mt1 = "05" Or mt1 = "07" Or mt1 = "08" Or mt1 = "10" Or mt1 = "12" ) And mt4 <= "31" ) Or _
(( mt1 = "04" Or mt1 = "06" Or mt1 = "09" Or mt1 = "11" ) And mt4 <= "30" ) Or ( mt1 = "02" And mt4 <= "28" ) Then
e.Text = Date.Today.Year & "-" & Mid(txt,1,5 )
Else
MessageBox.Show( "你输入的日子格式出錯!请以4位数字(月日)或6位数字(年月日),重新输入!")
e.Cancel = True
End If
ElseIf txt.Length > 0 And txt.Length <= 3 Then
MessageBox.Show( "你输入的日子格式出錯!请以4位数字(月日)或6位数字(年月日),重新输入!")
e.Cancel = True
End If
End If
这样,在辅助列输入4位数 " 0515" ,帶字符的5位数"05-15" 或 帶年份的6位数 "130515"
都会转化为"2013-05-15"
然后再用 gryy 的方法
把辅助列的值 .转为正常日子列里,假如输入的是不正常数值,如:"130231"
就提示出錯並需要更正为正常日子值.
虽然转了一个大弯,但总算滿足到美女们的懶惰输入方式了,
感谢各狐友提供方法和思路