[求助]关于模块的问题!
这段代码能否简化一下。其中哪些要放到公共模块中的?谢谢大家了Private Sub cmdUpdate_Click()
Dim con As New ADODB.Connection
Dim Rs As New Recordset
Dim Sql As String
If txtinfor(0).Text = "" Then
MsgBox "工号不能为空", vbExclamation + vbOKOnly, "提示"
Exit Sub
End If
If txtinfor(1).Text = "" Then
MsgBox "姓名不能为空", vbExclamation + vbOKOnly, "提示"
Exit Sub
End If
con.Open "Provider=SQLOLEDB.1;Password=***;Persist Security Info=True;User ID=***;Initial Catalog=MaxHRSec;Data Source=MAXSF-SQL"
Set Rs = New ADODB.Recordset
Sql = "select empno from AAAAA where empno='" & Trim(txtinfor(0).Text) & "'"
Rs.Open Sql, con, adOpenDynamic, adOpenKeyset
If Not Rs.EOF Then
MsgBox "有重复记录",vbExclamation + vbOKOnly, "提示"
Exit Sub
End If
With Adodc1.Recordset
.Fields(0).Value = txtinfor(0).Text
.Fields(1).Value = txtinfor(1).Text
.Fields(2).Value = txtinfor(2).Text
.Fields(3).Value = txtinfor(3).Text
.Fields(4).Value = txtinfor(4).Text
End With
Adodc1.Recordset.UpdateBatch adAffectAllChapters
MsgBox "添加成功", vbInformation + vbOKOnly, "提示"
Exit Sub
End Sub