0

我有一个访问表单,用户有时会忘记保存。我放了一个更新前触发器来弹出消息,提醒用户在采取任何行动之前保存或取消。
我在网上找到了这段代码,它适用于除“新记录”按钮之外的所有内容。
据我所知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
4

1 回答 1

0

我真的不明白是什么njno。如果文本框绑定到表单,RecordSource那么。表单Current事件使用:

Private Sub Form_Current ()

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

End Sub

然后在按钮 Click 事件上使用:

Private Sub new_Click()
DoCmd.GoToRecod,,acNewRec
End sub
于 2020-07-10T07:25:59.817 回答