If Left(Me.Txt2, 1) <> "0" Or Left(Me.Txt2, 1) <> "-" Then
MsgBox "无效数字首位必须是0"
Me.Txt2 = ""
Me.Txt2.SetFocus
Exit Sub
End If
End Sub
Private Sub Txt3_AfterUpdate()
If Left(Me.Txt3, 1) <> "0" Or Left(Me.Txt3, 1) <> "-" Then
MsgBox "无效数字首位必须是0"
Me.Txt3 = ""
Me.Txt3.SetFocus
Exit Sub
End If
End Sub
Private Sub Txt4_AfterUpdate()
If Left(Me.Txt4, 1) <> "0" Or Left(Me.Txt4, 1) <> "-" Then
MsgBox "无效数字首位必须是0"
Me.Txt4 = ""
Me.Txt4.SetFocus
Exit Sub
End If
End Sub
Private Sub Txt5_AfterUpdate()
If Left(Me.Txt5, 1) <> "0" Or Left(Me.Txt5, 1) <> "-" Then
MsgBox "无效数字首位必须是0"
Me.Txt5 = ""
Me.Txt5.SetFocus
Exit Sub
End If
End Sub
Private Sub Txt6_AfterUpdate()
If Left(Me.Txt6, 1) <> "0" Or Left(Me.Txt6, 1) <> "-" Then
MsgBox "无效数字首位必须是0"
Me.Txt6 = ""
Me.Txt6.SetFocus
Exit Sub
End If
End Sub
Private Sub Txt7_AfterUpdate()
If Left(Me.Txt7, 1) <> "0" Or Left(Me.Txt7, 1) <> "-" Then
MsgBox "无效数字首位必须是0"
Me.Txt7 = ""
Me.Txt7.SetFocus
Exit Sub
End If
End Sub
Private Sub Txt8_AfterUpdate()
If Left(Me.Txt8, 1) <> "0" Or Left(Me.Txt8, 1) <> "-" Then
MsgBox "无效数字首位必须是0"
Me.Txt8 = ""
Me.Txt8.SetFocus
Exit Sub
End If
End Sub作者: todaynew 时间: 2010-8-17 06:19
Sub 格式(ctl As Control)
Dim B As Boolean
B = Left(Me.txt1, 1) = "0" Or Left(Me.txt1, 1) = "-"
B = B And Len(Mid(ctl.Value, InStr(ctl.Value, "."))) <= 4
If B = False Then
ctl.Value = "格式错误!请重新输入!"
ctl.SetFocus
End If
End Sub
Private Sub txt1_AfterUpdate()
Call 格式(me.txt1)
End Sub
Private Sub Txt2_AfterUpdate()
Call 格式(me.txt2)
End Sub
作者: tmtony 时间: 2010-8-17 07:52
很简洁作者: xuwenning 时间: 2010-8-17 08:11
Sub 格式(ctl As Control)
Dim B As Boolean
B = Left(ctlValue , 1) = "0" Or Left(ctl Value, 1) = "-"
B = B And Len(Mid(ctl.Value, InStr(ctl.Value, "."))) <= 4
If B = False Then
ctl.Value = "格式错误!请重新输入!"
ctl.SetFocus
End If
End Sub
谢谢老汉