Hello everybody.
I have a form with a subform. The subform is a datasheet. I am trying to put a SAVE button on form ,so that records entered in subform are saved only when you click the button on the form.
I have create a hidden text field in the subform called buli which holds true or false and the code is below:
The code is preventing autosave but when I click save button it is not saving anything.
It looks like the problem is that as soon as I click the button, the before update event is called before starting to execute button click lines of code where buli becomes true, so buli remains false when entering before update sub. Please your suggestions
I have a form with a subform. The subform is a datasheet. I am trying to put a SAVE button on form ,so that records entered in subform are saved only when you click the button on the form.
I have create a hidden text field in the subform called buli which holds true or false and the code is below:
Code:
Private Sub Form_Current() 'çode on subfrom
Me.buli.Value = False
Me.buli.Properties("ColumnHidden") = True
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer) 'çode on subform
If Me.Dirty Then
If Me.buli.Value = False Then
Cancel = True
Me.Undo
Cancel = False
End If
End If
End Sub
Private Sub btnSave_Click() 'code on form
Forms!frmData!frmDataSubform.Form!buli.Value = True
Me.frmDataSubform.SetFocus
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord , , acNewRec
MsgBox ("Data saved")
Forms!frmData!frmDataSubform.Form!buli.Value = False
End Sub
It looks like the problem is that as soon as I click the button, the before update event is called before starting to execute button click lines of code where buli becomes true, so buli remains false when entering before update sub. Please your suggestions
Last edited: