Dim str As String
Dim i As Integer
Dim Rs As New ADODB.Recordset
If IsNull(Me![部门]) Then
MsgBox ("请输入部门!")
Me![部门].SetFocus
Else
Set Rs = New ADODB.Recordset
str = "select * from 部门"
Rs.Open str, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Rs.MoveFirst
For i = 1 To Rs.RecordCount
If Me![部门] = Rs("部门") Then
MsgBox ("部门已经存在!")
Exit Sub
Else
Rs.MoveNext
End If
Next i
With Rs '添加记录
.AddNew
!部门ID = Trim(Me![部门ID])
!部门 = Trim(Me![部门])
.Update
End With
Rs.Close
MsgBox ("添加成功!")
Me![部门 子窗体].Requery
Set Rs = Nothing