If you really wanted to annoy developers you'd probably design a system to work
like Access ADP.
Suppose you had a form bound to an underlying table and you were using it to
display and update records in continuous forms mode.
The form displays a tickbox bound to a bit field in the table. The idea is that
you can clear the tickboxes on any records and then click a button which will
delete any unchecked records.
You would notice in such a form that, if you updated any data and then exitted
from the form or clicked on "Show" then all updates would be performed properly
and as you would expect.
So, full of hope, you'd build something like this into the "Delete" button ..
'Use a stored procedure to delete non-live records ------
DeleteNonLive
'Refresh the form's data --------------------------------
Me.Requery
You'd call a subroutine to run a stored procedure to delete any records with an
unchecked field - and you'd expect this to work because you think that as soon
as the tickbox you've just unticked loses the focus, the current record will
be updated and your stored procedure wil do its stuff - and you'd be wrong.
The record you last changed does not have its changes sent back to the
database until Access has finished doing everything in the Delete button code.
So, in order to force an update you have to do the following in the Delete button...
'First save the current record --------------------------
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSaveRecord
'Use a stored procedure to delete non-live records ------
DeleteNonLive
'Refresh the form's data --------------------------------
Me.Requery
Just to complete the picture the subroutine "DeleteNonLive" looks like this:-
Sub DeleteNonLive()
Dim cmdCommand As ADODB.Command
Set cnConnection = CurrentProject.Connection
'Set up Command object -----------------------------------------
Set cmdCommand = New ADODB.Command
cmdCommand.ActiveConnection = cnConnection
cmdCommand.CommandType = adCmdText
cmdCommand.CommandText = "spDeleteNonLivePeople"
'Execute ------------------------------------------------------
cmdCommand.Execute
'Cleanup -------------------------------------------------------
Set cmdCommand = Nothing
cnConnection.Close
Set cnConnection = Nothing
End Sub
and the associated stored procedure is:-
CREATE PROCEDURE spDeleteNonLivePeople
AS
BEGIN
delete FROM tblPeople where Live=0
END