Add Save button to footer of main form.

T1080
T1080 used Ask the Experts™
on
I'd like to add a Save button to the footer of my main form.  My main form has a tab control on it, with four tabs.  Each tab has a subform.  How I'd like the save button to operate:  when the main form opens I have the save button disabled.  The save button should become enabled as soon as I make changes to the current tab/subform that has focus.  Also, if the save button is not hit (Me.dirty=True) and I try to move from the current tab to the subsequent I need a message box to pop up and ask to save the record.  And once Me.dirty=False, then the button should be disabled again.

Thank you,

Troy
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Can't be done.
Once you try to move from one subform to another or from subform to mainform, then Access will attempt to save the current record (assuming there has been a change).
You can intercept this within the Form_beforeupdate event procedure and ask the user if they want to save, but the only outcomes can be 'Yes' or 'No and undo changes'. Otherwise you cannot move off the subform.  
So you will never get the chance to click the save button except for changes to the main form where you don't also move into any of the subforms.

Author

Commented:
Makes Sense, how about If I put my save button on my subform as opposed to my main form?    I have code in my save button : if me.dirty = true then me.dirty = false end if.  Once clicked this fires code in my forms before update event (see code).  How can I get the before update to supress when I click the save button, but fire when I the form is dirty and I try to move to the next record for example?
Thanks,
Troy

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty = True Then
    If MsgBox("Would you like to Save your changes?", vbYesNo, "Save") = vbYes Then
    Else
        Me.Undo
    End If
End If
End Sub


Private Sub cmdSave_Click()
If Me.Dirty = True Then
    Me.Dirty = False
End If
End Sub

Open in new window

Set up a module level variable:
Dim OKtoSave as Boolean

In the cmdSave procedure do a new first line:
OKtoSave =true

and a new last line:
OKtoSave =false

In the FormBeforeupdate procedure do a new first line:
If OKToSave = true then
OKtosave = false
exit sub
end if

Author

Commented:
Thanks for the help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial