問題描述
帶有“新記錄”按鈕的更新前 (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
參考文件