帶有“新記錄”按鈕的更新前 (BeforeUpdate with a "new record" button)


問題描述

帶有“新記錄”按鈕的更新前 (BeforeUpdate with a "new record" button)

我有一個 Access 表單,用戶有時會忘記保存。我放入了一個 BeforeUpdate 觸發器來彈出消息,提醒用戶在採取任何操作之前保存或取消。
我在網上找到了這段代碼,它適用於除了我的“新記錄”之外的所有內容。按鈕。
據我所知,Me.Dirty 應該可以解決問題。

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
On Error GoTo Err_BeforeUpdate

' The Dirty property is True if the record has been changed.
If Me.Dirty Then
    ' Prompt to confirm the save operation.
    If MsgBox("Do you want to save?", vbYesNo + vbQuestion, _
      "Save Record") = vbNo Then
        Me.Undo
    End If
End If

Exit_BeforeUpdate:
Exit Sub

Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate

End Sub
</code></pre>

新記錄的代碼

Private Sub new_Click()
    njno = NewJobNbr()
    Job.Value = njno
    RnK.Value = ""
    Date_Requested.Value = ""
    Est_Time.Value = ""
    Originator.Value = ""
    Date_Required.Value = ""
    Description.Value = ""
    Reason_for_Request.Value = ""
    Comments.Value = ""
    Priority_Tasks.Value = ""
    TName.Value = ""
    Required.Value = ""
    Costing.Value = ""
    Completed.Value = ""
    Date_Completed.Value = ""
End Sub


參考解法

方法 1:

I don't really understand what njno is. If the textboxes are bound to the form's RecordSource then. On form Current event use:

Private Sub Form_Current ()

If Me.NewRecord Then
Job.Value = njno 
End if

End Sub

Then on the button Click event use:

Private Sub new_Click()
DoCmd.GoToRecod,,acNewRec
End sub

(by SimFil)

參考文件

  1. BeforeUpdate with a "new record" button (CC BY‑SA 2.5/3.0/4.0)

#ms-access-forms #vba #ms-access #beforeupdate






相關問題

DLookup 表達式總是返回相同的記錄 (DLookup expression always returning the same record)

MS-Access VBA - 如何將文本框使用的當前查詢字段名稱分配給變量 (MS-Access VBA - How to assign the current query field name used by a textbox to a variable)

MS Access 錯誤 3188:無法更新;當前被這台機器上的另一個會話鎖定 (MS Access Error 3188: Could not update; currently locked by another session on this machine)

將文本框值分配給多個表/查詢字段值 (Assigning a textbox value to a multiple table/query field values)

從訪問表單的文本字段傳遞開始和結束日期參數 (Pass start and end date parameter from text field of access form)

如何根據來自兩個組合框的輸入隱藏/取消隱藏子表單? (How do I hide/unhide a subform based on the input from two comboboxes?)

ms訪問表單:組合框到多選下拉菜單 (ms access form: combobox to multiselect dropdown menu)

訪問表單宏 Where 條件 (Access Form Macro Where Condition)

(Microsoft Access) 如何輸入多個新記錄,其中 5 個字段中有 2 個被重置 ((Microsoft Access) How to Input multiple new records with 2 out of 5 fields from being reset)

帶有“新記錄”按鈕的更新前 (BeforeUpdate with a "new record" button)

MS Access 表單日期/時間輸入問題 (MS Access Forms Date/Time Entry Trouble)







留言討論