Welcome to Windows Help!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Implementing Save and Cancel command buttons on a form

 
   Windows Help (Home) -> Microsoft Access RSS
Next:  Export a Word DOC document as PPT PowerPoint  
Author Message
David G.

External


Since: Dec 10, 2009
Posts: 4



(Msg. 1) Posted: Thu Feb 18, 2010 12:34 pm
Post subject: Implementing Save and Cancel command buttons on a form
Archived from groups: microsoft>public>access (more info?)

I am having issues enabling and disabling Save and Cancel buttons on a
form in continuous form view. I'm using the Dirty and Current events
to enable and disable as the user tabs or clicks through records.
(Works fine.)

For cancel, I move the focus to any of the form fields, then disable
Cancel. With Save, if I move the focus to a form field, it selects the
active record row instead of moving onto a new record.

Does any one know of an example I might see how this scenario is best
handled?
THANKS!
THANKS!
David G.

 >> Stay informed about: Implementing Save and Cancel command buttons on a form 
Back to top
Login to vote
KenSheridan via AccessMon

External


Since: Aug 17, 2009
Posts: 20



(Msg. 2) Posted: Thu Feb 18, 2010 2:25 pm
Post subject: Re: Implementing Save and Cancel command buttons on a form
Archived from groups: per prev. post (more info?)

FWIW here's the code from the module a form with Save and Undo buttons, in
which I've added a line to move to a new record after a save, and commented
out the lines which in my original, where focus remains on the current record,
disable the buttons. These are unnecessary as this is covered by the Current
event procedure's code:

' 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
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
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
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

David G. wrote:
>I am having issues enabling and disabling Save and Cancel buttons on a
>form in continuous form view. I'm using the Dirty and Current events
>to enable and disable as the user tabs or clicks through records.
>(Works fine.)
>
>For cancel, I move the focus to any of the form fields, then disable
>Cancel. With Save, if I move the focus to a form field, it selects the
>active record row instead of moving onto a new record.
>
>Does any one know of an example I might see how this scenario is best
>handled?
>THANKS!
>THANKS!
>David G.

 >> Stay informed about: Implementing Save and Cancel command buttons on a form 
Back to top
Login to vote
KenSheridan via AccessMon

External


Since: Aug 17, 2009
Posts: 20



(Msg. 3) Posted: Thu Feb 18, 2010 2:25 pm
Post subject: Re: Implementing Save and Cancel command buttons on a form
Archived from groups: per prev. post (more info?)

PS: I should have mentioned that if the user closes the form while a record
is Dirty the record is not saved; the form just discards the changes then
closes. The Save button is the only way to save the record.

Ken Sheridan
Stafford, England
 >> Stay informed about: Implementing Save and Cancel command buttons on a form 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
create a button to save form in pdf - Hello everyone I need to create a button on a form that would save the form in pdf format. I don’t know how to do that? any help will be greatly appreciated. thank you very much

How to set field from VBA on Form Save - Hello I have a data entry form with a label that displays a running timer hh:mm:ss. The value displayed on the timer label must be saved to the TimeSpent field of the table when the form is saved. How can I set the TimeSpent field in the current unsave...

Command button?? - I have a database of a whole bunch of contacts..now what Im trying for now is to get like a box that pops up BEFORE the list of contacts comes up that is like a little search boc that will find a particular contact for me..get it? for instance when i....

VB Command - I have a button that runs the function below. It opens an excel document. I also have other funtion that opens up other documents whether it be a word or pdf docuement. This command opens each document in an explorer window. How can I make a generic...

Inactivate command button when no records - I have a subform that shows multiple records (notes) per client. In the subform header are navigation buttons including a button to create a new record. I have successfully programmed the buttons to disable when there is no more records in their directio...
   Windows Help (Home) -> Microsoft Access All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]