Saving

  • Thread starter Thread starter Clinton
  • Start date Start date
C

Clinton

Hallo,

I use the following code for saving a record. A botton for saving and a
confirmation in the before update event. Idea is that the user has to
confirm the change/save. The below code works fine. The save triggers the
before update.

But now i actualy have 2 save code (save button and beforeupdate (triggerd
by the save button)). Can i combine this so only the before update save
action is used or moving it to another place. Tried various combinations but
can't find another way that gets rid of the cmdSave save action...


--code start 1--
Private Sub CmdSave_Click()
On Error GoTo Err_CmdSave_Click

DoCmd.RunCommand acCmdSaveRecord

Exit_CmdSave_Click:
Exit Sub

Err_CmdSave_Click:
MsgBox Err.Description
Resume Exit_CmdSave_Click

End Sub
--code end 1--

--code start2--
Private Sub Form_BeforeUpdate(Cancel As Integer)
Msg = "Update changes?"
Style = vbYesNo + vbQuestion
Title = "Customers"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
'close
Else
DoCmd.RunCommand acCmdUndo
End If

End Sub
--code end2--

Thanx in advance for any tips.

Regards
 
I really don't understand your problem?

The only code you have for your save button is:
DoCmd.RunCommand acCmdSaveRecord

You really only need the above one line of code. All of the prompting, and
stuff you have in the ONE beforeupdate event looks good to me, and can
remain in the one spot.

I really can't imagine anything much better then what you have. I don't see
any issues of increased maintains, or difficult here.

Of course, dumping the save button all together would probably be the best
solution. ms-access has worked that way for 10 years now!
 
Back
Top