A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Save Button



 
 
Thread Tools Display Modes
  #1  
Old April 26th, 2010, 07:16 PM posted to microsoft.public.access
Emma
external usenet poster
 
Posts: 493
Default Save Button

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?
  #2  
Old April 26th, 2010, 07:22 PM posted to microsoft.public.access
Emma
external usenet poster
 
Posts: 493
Default Save Button

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?

  #3  
Old April 26th, 2010, 08:31 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Save Button

On Mon, 26 Apr 2010 11:22:01 -0700, Emma
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]
  #4  
Old April 26th, 2010, 11:31 PM posted to microsoft.public.access
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Save Button

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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:01 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.