Do not add to table until

steve711

Registered User.
Local time
Today, 15:17
Joined
Mar 25, 2004
Messages
166
I think this would be simple but I don't see the light on it.

I have a form linked of course to a table. On this form I have a button that says SAVE and when the user clicks it a popup then asks are you sure YES NO...If they are sure YES then I want the data in the form to be saved or sent to the table (not sure on the terminology). If NO then it allows them to go back to the form. Should they decide it is all wrong then closing the form records nothing.

I believe in order to do this it is in the way I open the form. Or maybe I am completely wrong.

Thanks for the push in the right direction.
 
Try pasting this code in command button (on click event)

Private Sub Command31_Click()
Dim strMsg As String, strTitle As String

strMsg = "Do You Want To Save This Record?"
strTitle = " Save Record ?"

If MsgBox(strMsg, vbQuestion + vbYesNo, strTitle) = vbNo Then
Me.Undo

End If

DoCmd.GoToRecord , , acNewRec

End Sub


Set your form cycle to current record.

hth,
Michael
 
Try this..
Code:
Private Sub bSave_Click()
On Error GoTo Err_bSave_Click

    Beep
    Select Case MsgBox("Do you want to save your changes to the current record?" & vbCrLf & vbLf & "  Yes:         Saves Changes" & vbCrLf & "  No:          Does NOT Save Changes" & vbCrLf & "  Cancel:    Reset (Undo) Changes" & vbCrLf, vbYesNoCancel + vbQuestion, "Save Current Record?")
        Case vbYes: 'Save the changes
            DoCmd.RunCommand acCmdSaveRecord

        Case vbNo: 'Do not save or undo
            'Do nothing

        Case vbCancel: 'Undo the changes
            DoCmd.RunCommand acCmdUndo

        Case Else: 'Default case to trap any errors
            'Do nothing

    End Select

Exit_bSave_Click:
    Exit Sub

Err_bSave_Click:
    If Err = 2046 Then 'The command or action Undo is not available now
        Exit Sub
    Else
        MsgBox Err.Number, Err.Description
        Resume Exit_bSave_Click
    End If
    
End Sub

Check out my A better mouse trap? sample for a twist on controling the users mouse wheel in regards to saving [not saving] record changes if the current record is dirty.
 
My A better mouse trap? sample does basically the same thing with how I am tesing if the record is okay to save or not in the forms BeforeUpdate event.
 

Users who are viewing this thread

Back
Top Bottom