Do not insert record and discard input on form

swee

Registered User.
Local time
Today, 10:48
Joined
Aug 11, 2004
Messages
66
I have a data entry form. Let's say I have filled up all the required fields in the main and sub form, and then I decide not to save the form. I want to have a button that upon clicking, will discard all the data on the form and not save it in the tables. How do I write the required code? Currently I have thought of this:

Code:
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 , , acLast

However Me.Undo only gets rid of the data entered in the main form before the focus enters the subform. I think Undo is not the way to delete the record in the table. Appreciative of any input. Thanks a lot!
 
Swee,

By the time you've finished entering all of the info into the subform, Access
has long since committed the changes to the database. You're going to
need a Delete button on your form.

The button can run a Delete query, or some VBA code, to delete the main
and child records.

Wayne
 
Thanks for the feedback and suggestions. I added a button and on its click event, i added the following code:

strSQL = " DELETE *" & _
" FROM tblName" & _
" WHERE CritieriaField = '" & Me.txtCriteriaField& "'"

CurrentDb.Execute strSQL

Me.Requery

It managed to delete the record in the main and subform. Phew.
 

Users who are viewing this thread

Back
Top Bottom