|
第三项功能描述:
功能:点击“保存”会先验证是否重复,无重则保存入数据库。(本语法由MDB移植过来,在ADP中不能执行)
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
Dim SQL As String
Dim i As Integer
Dim STEMP As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
'判断窗体名是否为空
If IsNull(Me![窗体名]) Then
MsgBox "请输入要添加的窗体名!", 64, "错误"
Me.窗体名.SetFocus
'判断窗体名是否重复
ElseIf Me![窗体名] = DLookup("窗体名", "系统窗体", "窗体名='" & Me![窗体名] & "'") Then
MsgBox "此窗体名已经存在!", 64, "错误"
Me.窗体名.SetFocus
Me![窗体名] = Null
Else
DoCmd.SetWarnings False
'向系统窗体表中添加新增窗体相关记录
SQL = "INSERT INTO 系统窗体 ( 窗体ID, 窗体名 )" & _
"SELECT [Forms]![系统权限管理]![窗体ID] AS 窗体ID, [Forms]![系统权限管理]![窗体名] AS 窗体名"
DoCmd.RunSQL SQL
'向“系统权限”表中添加新增窗体相关记录,
STEMP = "Select * From 系统权限"
rs.Open STEMP, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For i = 0 To DMax("ID", "系统权限")
rs.AddNew
rs("窗体ID") = Me![窗体ID]
rs("ID") = i
rs("权限") = "无权"
rs.Update
Next i
Me.frmsub.Requery
Set rs = Nothing
Me![窗体ID] = Null
Me![窗体名] = Null
MsgBox "新窗体生成成功!" & Chr(40) & Chr(40) & _
"所有生成的新窗体权限设为默认“无权”" & Chr(10) & _
"需要对权限进行分配", 64, " "
DoCmd.SetWarnings True
End If
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description, 16, "出错"
Resume Exit_cmdSave_Click
End Sub |
|