-- 作者:狐狸爸爸
-- 发布时间:2015/4/19 15:43:00
--
代码逻一塌糊涂,一个简单的赋值也能写成这样,冗余代码如此之多,条理如此混乱,能正确执行才奇怪,你还不如直接告诉你的需求,重写代码。
我帮你重写了,但是不保证正确,因为不知道你的需求:
With e.form With e.form If .Controls("TextBox5").Value Is Nothing Then MsgBox("部门编号不能为空!",64, "提示") Tables("bmgl").AllowEdit = False Return End If If .Controls("TextBox6").Value Is Nothing Then MsgBox("部门编号不能为空!",64, "提示") Tables("bmgl").AllowEdit = False Return End If If .Controls("TextBox7").value IsNot Nothing AndAlso Isnumeric( .Controls("TextBox7").value) =False Then MsgBox("电话号码只能为数字!",64, "提示") Tables("bmgl").AllowEdit = False Return End If If Tables("bmgl").Current("bmbh") = .Controls("TextBox6").value Then Tables("bmgl").Current("bmmc") = .Controls("TextBox5").value Tables("bmgl").Current("bmbh")= .Controls("TextBox6").value Tables("bmgl").Current("tel")= .Controls("TextBox7").value Tables("bmgl").Current("mail")= .Controls("TextBox8").value Tables("bmgl").Current("bz")= .Controls("TextBox9").value Else Dim r As Integer r = Tables("bmgl").find( .Controls("TextBox6").value , 0, 0, False, False, True) If r > -1 Then msgbox("部门编号已存在,请更正!",64,"提示") .Controls("TextBox6").text =Tables("bmgl").Current("bmbh") Else Tables("bmgl").Current("bmmc") = .Controls("TextBox5").value Tables("bmgl").Current("bmbh")= .Controls("TextBox6").value Tables("bmgl").Current("tel")= .Controls("TextBox7").value Tables("bmgl").Current("mail")= .Controls("TextBox8").value Tables("bmgl").Current("bz")= .Controls("TextBox9").value Tables("bmgl").Current.Save End If End If .Controls("TextBox5").value ="" .Controls("TextBox6").value ="" .Controls("TextBox7").value ="" .Controls("TextBox8").value ="" .Controls("TextBox9").value ="" End With End With
[此贴子已经被作者于2015/4/19 16:01:07编辑过]
|
-- 作者:狐狸爸爸
-- 发布时间:2015/4/19 16:05:00
--
再来,这样更简单点:
With e.form With e.form If .Controls("TextBox5").Value Is Nothing Then MsgBox("部门编号不能为空!",64, "提示") Tables("bmgl").AllowEdit = False Return End If If .Controls("TextBox6").Value Is Nothing Then MsgBox("部门编号不能为空!",64, "提示") Tables("bmgl").AllowEdit = False Return End If If .Controls("TextBox7").value IsNot Nothing AndAlso Isnumeric( .Controls("TextBox7").value) =False Then MsgBox("电话号码只能为数字!",64, "提示") Tables("bmgl").AllowEdit = False Return End If If Tables("bmgl").Current("bmbh") <> .Controls("TextBox6").value Then If DataTables("bmgl").find( "bmbh = \'" & .Controls("TextBox6").value & "\'") IsNot Nothing Then msgbox("部门编号已存在,请更正!",64,"提示") .Controls("TextBox6").text =Tables("bmgl").Current("bmbh") Return End If End If Tables("bmgl").Current("bmmc") = .Controls("TextBox5").value Tables("bmgl").Current("bmbh")= .Controls("TextBox6").value Tables("bmgl").Current("tel")= .Controls("TextBox7").value Tables("bmgl").Current("mail")= .Controls("TextBox8").value Tables("bmgl").Current("bz")= .Controls("TextBox9").value Tables("bmgl").Current.Save .Controls("TextBox5").value ="" .Controls("TextBox6").value ="" .Controls("TextBox7").value ="" .Controls("TextBox8").value ="" .Controls("TextBox9").value ="" End With End With
以后这么长的代码,最好也告知你的需求和设计逻辑,因为你的代码本就混乱,别人无法准确看出你要做什么。
[此贴子已经被作者于2015/4/19 16:42:48编辑过]
|