问题
I have a bound form in MS Access and I use a submit button to insert the data from form to table. I have around 10 fields in form and even if I fill only 1 field and press the F5 button, it saves the data with just one field. How to stop F5 key from doing this.
Edit - also when I close the form with partially filled data or if it gets closed accidently or when if i open design mode from there, it collects that partially filled data and then creates an entry, how to stop userform making entries via other means and make it only create record on button click.
回答1:
In my opinion, you should not stop the F5 button from doing this, you should stop anything else than your submit button from saving data.
This can be achieved with some VBA code:
The save button is named cmdSave in this example
Private saveButtonPressed As Boolean
Private Sub cmdSave_Click()
saveButtonPressed = True
DoCmd.RunCommand acCmdSaveRecord
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
If Not saveButtonPressed Then
'Update through other means
Cancel = True
End If
saveButtonPressed = False
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not saveButtonPressed Then
'Update through other means
Cancel = True
End If
saveButtonPressed = False
End Sub
来源:https://stackoverflow.com/questions/47682667/how-to-prevent-f5-key-from-saving-data-from-userform-in-access