我有一个用户有时忘记保存的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新记录的代码
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发布于 2020-07-10 15:26:00
我真的不太明白njno是什么。如果文本框被绑定到窗体的RecordSource,那么。在form Current事件中使用:
Private Sub Form_Current ()
If Me.NewRecord Then
Job.Value = njno
End if
End Sub然后单击按钮Click event use:
Private Sub new_Click()
DoCmd.GoToRecod,,acNewRec
End subhttps://stackoverflow.com/questions/58845478
复制相似问题