|
“保存”的单击事件中加入代码
Private Sub Command10_Click()
On Error GoTo Err_Command10_Click
Dim str As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
str = "select * from 表2"
rs.Open str, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If IsNull(Me.日期) Then
MsgBox "日期-不能为空", , "错误"
Me.日期.SetFocus
Exit Sub
ElseIf IsNull(Me.消费分类) Then
MsgBox "消费分类-不能为空", , "错误"
Me.消费分类.SetFocus
Exit Sub
ElseIf IsNull(Me.Text6) Then
MsgBox "金额-不能为空", , "错误"
Me.Text6.SetFocus
Exit Sub
End If
If MsgBox("确定要保存吗?", vbYesNo, "保存前确认") = vbYes Then
rs.AddNew
rs!日期 = Me.日期
rs!消费分类 = Me.消费分类
rs!金额 = Me.Text6
rs.Update
MsgBox Me.消费分类.Column(1) & " 已保存"
Me.[表2 子窗体].Requery
Else
MsgBox "已取消保存"
End If
rs.Close
Set rs = Nothing
Exit_Command10_Click:
Exit Sub
Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click
End Sub |
|