Cancel Current Record Input

milkman2500

Registered User.
Local time
Today, 13:28
Joined
Oct 21, 2012
Messages
45
Hi,

I've read a few other threads about this but the suggestions offered didn't work for me. I'm hoping I can paste my code here and someone might be able to help.

I want a message box to appear when the user clicks "Ok". The message back should ask the user to confirm adding a new client. If they click cancel, I want the form to close and no new record to be added to the underlying table. If they click Ok, I want the record to be added to the table and the form to close.

Code:
Private Sub submit_button_Click()
Dim response As Integer
response = MsgBox("Are you sure you want to add this new client?", vbOKCancel, "Confirm adding new client")
If response = vbOK Then
    DoCmd.Close acForm, "addClient", acSaveNo
Else
    DoCmd.RunCommand acCmdDeleteRecord
    
    DoCmd.Close acForm, "addClient", acSaveNo
End If

End Sub
 
Code:
Private Sub submit_button_Click()
Dim response As Integer
response = MsgBox("Are you sure you want to add this new client?", vbOKCancel, "Confirm adding new client")
If response = vbOK Then
    DoCmd.Close acForm, "addClient", acSaveNo
Else
[B][COLOR=red]    Me.Undo[/COLOR][/B]    
    DoCmd.Close acForm, "addClient", acSaveNo
End If

End Sub
 
I think it would be better to have a button that closes the form. You could set its Caption property to "Save" if you wish. Then put all the validation code in the forms Before Update event.
As it stands, the user will save a new record automatically by moving to a different record or by closing the form without the "Save" button.
 
I agree with Bob, here, and FYI, the acSaveNo on the Close Command has nothing to do with saving or not saving the Record; it refers to saving or not saving any Design Changes that have been made to the Form.

Also, your line

DoCmd.RunCommand acCmdDeleteRecord

doesn't work, in this situation, because the 'Record' at hand isn't really a Record, yet, as it hasn't been saved at this point in time.

Linq ;0)>
 
Thanks for the replies! I was planning on only have the 2 buttons ("Submit" or "Cancel"). I changed the form properties to only allow record navigation within the current record and to remove the close form option, other than the "Cancel" button.

I'll try your suggestion for the Undo command and remove the save commands.
 

Users who are viewing this thread

Back
Top Bottom