From: Emma on
Hi I have a from where I would like the user to be able to click a save
button instead of Ctrl+S can anyone help me with this?
From: Emma on
Is it just DoCmd.RunCommand acCmdSaveRecord

"Emma" wrote:

> Hi I have a from where I would like the user to be able to click a save
> button instead of Ctrl+S can anyone help me with this?
From: John W. Vinson on
On Mon, 26 Apr 2010 11:22:01 -0700, Emma <Emma(a)discussions.microsoft.com>
wrote:

>Is it just DoCmd.RunCommand acCmdSaveRecord

Either that; or the Save Record action in a Macro; or

If Me.Dirty Then Me.Dirty = False

will also work.

It's generally not necessary to have a Save button, since the record will be
saved automatically when you move off the record or close the form, but some
users find it reassuring.
--

John W. Vinson [MVP]
From: KenSheridan via AccessMonster.com on
If you want the user to be able to save a record *only* via the Save button,
the following is the code from the module of a form which does this, with
user confirmation via a message box when the button is clicked; which can
easily be removed if preferred. It also includes an Undo button and the Save
and Undo buttons are disabled when there is no edited record to save:

' updates can only be saved via command button
Option Compare Database
Option Explicit

Dim blnSaved As Boolean

Private Sub cmdSave_Click()

Const MESSAGETEXT = "Save record?"

If Me.Dirty Then
' if user confirms set variable to True and attempt to save record
If MsgBox(MESSAGETEXT, vbQuestion + vbYesNo, "Confirm") = vbYes Then
blnSaved = True
On Error Resume Next
RunCommand acCmdSaveRecord
' if record cannot be saved set variable to False
If Err <> 0 Then
blnSaved = False
Else
' disable buttons
' move focus to another control first
Me.AddressID.SetFocus
'Me.cmdSave.Enabled = False
'Me.cmdUndo.Enabled = False
' Move to new record
DoCmd.GoToRecord acForm, Me.Name, acNewRec
End If
Else
blnSaved = False
End If
End If

End Sub

Private Sub cmdUndo_Click()

' undo edits
Me.Undo
' disable buttons
' move focus to another control first
Me.AddressID.SetFocus
Me.cmdSave.Enabled = False
Me.cmdUndo.Enabled = False

End Sub

Private Sub Form_AfterUpdate()

' reset variable to False
blnSaved = False

End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)

' cancel update if variable is False,
' i.e. save button has not been clicked
If Not blnSaved Then
Cancel = True
End If

End Sub

Private Sub Form_Current()

' reset variable to False
blnSaved = False
' disable buttons
' move focus to another control first
Me.cmdSave.Enabled = False
Me.cmdUndo.Enabled = False

End Sub

Private Sub Form_Dirty(Cancel As Integer)

' enable buttons
Me.cmdSave.Enabled = True
Me.cmdUndo.Enabled = True

End Sub

Private Sub Form_Error(DataErr As Integer, Response As Integer)

Const IS_DIRTY = 2169

' suppress system error message if form
' is closed while record is unsaved,
' NB: changes to current record will be lost
If DataErr = IS_DIRTY Then
Response = acDataErrContinue
End If

End Sub

Ken Sheridan
Stafford, England

Emma wrote:
>Is it just DoCmd.RunCommand acCmdSaveRecord
>
>> Hi I have a from where I would like the user to be able to click a save
>> button instead of Ctrl+S can anyone help me with this?

--
Message posted via http://www.accessmonster.com