Private Sub Command1_Click()
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Dim sql As String
If Trim(txtdepartnum.Text) = "" Then
MsgBox "添加部门编号不能为空", vbOKOnly + vbExclamation, ""
txtdepartnum.SetFocus
Exit Sub
End If
If Trim(txtdepartname.Text) = "" Then
MsgBox "添加部门名称不能为空", vbOKOnly + vbExclamation, ""
txtdepartname.SetFocus
Exit Sub
End If
If Trim(txtmanager.Text) = "" Then
MsgBox "添加部门经理不能为空", vbOKOnly + vbExclamation, ""
txtmanager.SetFocus
Exit Sub
End If
If Trim(txtintro.Text) = "" Then
MsgBox "添加部门简介不能为空", vbOKOnly + vbExclamation, ""
txtintro.SetFocus
Exit Sub
End If
conn.Open "provider=Microsoft.Jet.OLEDB.4.0; data source=" & App.Path & "\miscowa.mdb"
sql = "select * from department where id=' " & Trim(txtdepartnum.Text) & "'"
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
Set rs = getrs(sql)
If rs.RecordCount > 0 Then
MsgBox "该编号的部门已经存在!", vbInformation, "提示"
Else
rs.AddNew
rs("id").Value = txtdepartnum.Text
rs("name").Value = txtdepartname.Text
rs("manager").Value = txtmanager.Text
rs("intro").Value = txtintro.Text
rs.Update
MsgBox "添加部门记录成功", vbInformation, "提示"
rs.Close
Set rs = Nothing
End If
End Sub