我搞定了,完整代码如下:
Private Sub tianjia_Click()
If Trim(add.xm.text) = Empty Then
MsgBox "客户姓名没有填写!", vbInformation, "系统提示"
add.xm.SetFocus
Exit Sub
End If
If Len(add.xm.text) > 20 Then
MsgBox "客户姓名不能大于20位字符!", vbInformation, "系统提示"
add.xm.SetFocus
Exit Sub
End If
If Trim(add.dh.text) = Empty Then
MsgBox "客户联系电话没有填写!", vbInformation, "系统提示"
add.dh.SetFocus
Exit Sub
End If
If Not IsNumeric(add.dh.text) Then
MsgBox "联系电话应该是数字吧,请重输入!", vbInformation, "系统提示"
add.dh.SetFocus
Exit Sub
End If
If Len(add.dh.text) > 11 Then
MsgBox "手机号码也只有11位哦,请重新输入!", vbInformation, "系统提示"
add.dh.SetFocus
Exit Sub
End If
If Trim() <> Empty Then
If Not IsNumeric() Then
MsgBox "备用号码请输入数字!", vbInformation, "系统提示"
Exit Sub
End If
End If
If Len() > 11 Then
MsgBox "手机号码也只有11位哦,请重新输入!", vbInformation, "系统提示"
Exit Sub
End If
If Trim(add.zz.text) = Empty Then
MsgBox "客户家庭住址没有填写!", vbInformation, "系统提示"
add.zz.SetFocus
Exit Sub
End If
If Len(add.zz.text) > 30 Then
MsgBox "输入的客户家庭住址不得超过30个字符", vbInformation, "系统提示"
add.zz.SetFocus
Exit Sub
End If
If Trim() = Empty Then
MsgBox "请选择适当的机型分类!", vbInformation, "系统提示"
Exit Sub
End If
If Len() > 10 Then
MsgBox "输入机型分类不能超过10个字符!", vbInformation, "系统提示"
Exit Sub
End If
If Trim() = Empty Then
MsgBox "请选择适合的显示屏品牌!", vbInformation, "系统提示"
Exit Sub
End If
If Len() > 10 Then
MsgBox "输入显示屏品牌不能超过10个字符!", vbInformation, "系统提示"
Exit Sub
End If
If Len() > 15 Then
MsgBox "输入显示屏型号不能超过15个字符!", vbInformation, "系统提示"
Exit Sub
End If
If Trim(add.psn.text) = Empty Then
MsgBox "显示屏序列号/SN编码不能为空!", vbInformation, "系统提示"
add.psn.SetFocus
Exit Sub
If Trim() = Empty Then
MsgBox "请选择适合的显示屏保点情况!", vbInformation, "系统提示"
Exit Sub
End If
End If
If Trim(add.jp.text) = Empty Then
MsgBox "新主机品牌不能为空!", vbInformation, "系统提示"
add.jp.SetFocus
Exit Sub
End If
If Trim(add.jx.text) = Empty Then
MsgBox "请输入新主机型号!", vbInformation, "系统提示"
add.jx.SetFocus
Exit Sub
End If
If Trim(add.jsn.text) = Empty Then
MsgBox "电脑主机序列号/SN编码不能为空!", vbInformation, "系统提示"
add.jsn.SetFocus
Exit Sub
End If
If Trim() = Empty Then
MsgBox "请选择预保修模式!", vbInformation, "系统提示"
Exit Sub
End If
If Trim(add.ldy.text) = Empty Then
MsgBox "系统录单员姓名不能为空!", vbInformation, "系统提示"
add.ldy.SetFocus
Exit Sub
End If
If Trim(add.shr.text) = Empty Then
MsgBox "系统审核员姓名不能为空!", vbInformation, "系统提示"
add.shr.SetFocus
Exit Sub
End If
Call con
Rs.Open "select * from [kf]", Cnn, 3, 3
Do While Not Rs.EOF
If Trim(add.xm.text) = Rs.Fields("name") And Trim(add.jsn.text) = Rs.Fields("pcsn") Then
MsgBox "要添加的客户已存在,请勿重复添加!", vbInformation, "系统提示!"
add.tianjia.Enabled = False
add.xiugai.Enabled = True
add.shanchu.Enabled = False
add.beifen.Enabled = False
add.huifu.Enabled = False
Rs.Close
Cnn.Close
Exit Sub
End If
Rs.MoveNext
Loop
Rs.AddNew
Rs.Fields("name") = Trim(add.xm.text)
Rs.Fields("tel") = Val(add.dh.text)
Rs.Fields("phone") = Val()
Rs.Fields("addr") = Trim(add.zz.text)
Rs.Fields("lei") = Trim()
Rs.Fields("xpai") = Trim()
Rs.Fields("xxing") = Trim(add.px.text)
Rs.Fields("xsn") = Trim(add.psn.text)
Rs.Fields("xdate") = DT1.Value
Rs.Fields("xbx") = DT2.Value
Rs.Fields("bd") = Trim()
Rs.Fields("zpai") = Trim(add.jp.text)
Rs.Fields("xing") = Trim(add.jx.text)
Rs.Fields("pcsn") = Trim(add.jsn.text)
Rs.Fields("fs") = Trim()
Rs.Fields("sdate") = DT3.Value
Rs.Fields("bdate") = DT4.Value
Rs.Fields("luser") = Trim(add.ldy.text)
Rs.Fields("lchk") = Trim(add.shr.text)
Rs.Update
MsgBox "客户信息添加成功", vbCritical, "系统提示!"
Rs.Close
Cnn.Close
Set Rs = Nothing
Set Cnn = Nothing
Unload add
With main.ListView1
.ListItems.Clear
End With
Call tree_change
End Sub
Public Sub tree_change()
Call con
Dim key, text As String
Dim nod As Node
With main.TreeView1
.Nodes.Clear
Set node1 = .Nodes.add(, , "客户名单", "客户名单", 1)
End With
asing = "select * from [kf]"
Rs.Open asing, Cnn, 3, 3
Do While Not Rs.EOF
text = Trim(Rs.Fields("name").Value)
With main.TreeView1
Set node2 = .Nodes.add("客户名单", tvwChild, , text, 1)
End With
Rs.MoveNext
Loop '循环语句
Rs.Close '循环完后 就关闭记录集
Cnn.Close
With main.TreeView1
.HotTracking = True
For i = 1 To .Nodes.Count
.Nodes(i).Expanded = False
Next i
End With
Set Rs = Nothing
Set Cnn = Nothing