Access 2013:如何控制哪些表单更改已保存以及哪些表单被取消

时间:2017-01-28 16:12:58

标签: forms ms-access-2013

我有一个包含3个按钮的表单:

保存 - 保存表单

NewReport - 仅在保存当前表单后才可见,并且应该清除表单并让用户输入另一种形式的数据。

关闭 - 应关闭应用程序而不保存未完成的表单。

我似乎无法弄清楚如何使用Before Update事件过程控制这些功能。

我不明白的一件事是,在我以某种方式更改表单的焦点之前,Save命令实际上并没有将数据转到表中。因此,如果我的用户输入数据并点击“保存”按钮,则在保存命令完成时,表格尚未保存数据。它只会在焦点变化后出现在表格中;喜欢来自Requery。

以下是我当前版本的代码:

Option Compare Database
Option Explicit

Private Cause As Variant

Private Sub btnClose_Click()

    Cause = "CloseButton"
    DoCmd.Close acForm, "frmReports", acSaveNo

End Sub

Private Sub btnNewReport_Click()

    Cause = "NewReport"
    Me.Requery
    Me.RepStatus = ""

End Sub

Private Sub cmdSave_Click()

    Dim outl As Outlook.Application
    Dim mi As Outlook.MailItem

    'blnGood = True
    Cause = "SaveButton"

    'Save the Record
    DoCmd.Save acForm, "frmReports"

'    If Me.DateOfVisit <> "" Then
        Me.RepStatus = "Report Saved!"
'        Set outl = New Outlook.Application
'        Set mi = outl.CreateItem(olMailItem)
'            mi.Body = "A new report was just recorded."
'            mi.Subject = Application.CurrentUser & " Just Logged a Report."
'            mi.To = "rich.temen@cox.net"
'            mi.Send
'
'        Set mi = Nothing
'        Set outl = Nothing
'    End If

End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim strMsg As String

    Select Case Cause
        Case "SaveButton"
            Me.btnNewReport.Visible = True
            'do nothing

        Case "NewReport"
            'di this

        Case "CloseButton"
            Me.Undo

    End Select

    'If Not blnGood Then
     '   strMsg = "Please use the Save button to save your Report," & _
    '             vbNewLine & "or Escape to reset the form."
    '    Call MsgBox(Prompt:=strMsg, Title:="Before Update")
    'End If
End Sub

Private Sub Form_Load()

    Me.btnNewReport.Visible = False
    Cause = ""

End Sub

感谢您对此提供任何帮助,我已经在圈子里走了几个小时。

0 个答案:

没有答案