Preventing close buttons from saving records in MS Access

后端 未结 6 1191
小蘑菇
小蘑菇 2021-02-10 11:42

In a Microsoft Access form, whenever the current record changes, any changes in bound controls are silently saved to the database tables. This is fine, but I don\'t want it to h

6条回答
  •  隐瞒了意图╮
    2021-02-10 12:34

    You have to work with Form_BeforeUpdate event. Below is an example; however it does create a typical warning message: "You can't save this record at this time. Microsoft Access may have encountered an error while trying to save a record. ..." - depending on your database settings. You can use simple workaround below to avoid displaying of that message.

    Private Sub Form_BeforeUpdate(Cancel As Integer)
       Cancel = True
       'Or even better you can check certain fields here (If Then...)
    
    End Sub
    
    
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
        If DataErr = 2169 Then 
            Response = True
        End If
    End Sub
    

提交回复
热议问题