I have another question in mind. 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:
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
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. How do I achieve that? Appreciative of any input. Thanks!
Last edited by machix; 09-03-04 at 05:54.
You have to write a delete query to delete this record, using the id (or whatever) on the form as parameter value (s).
Same to do if the 'undo' button is outside the subform.
However, next statement is easier:
Just as an unrelated "aside" .. when you are referring to things in Microsoft Access, always change the names of controls so that they are slightly-different from the names of database fields. There is an ambiguity otherwise, that can bite you.
What do you mean by next piece of code. I put it in the click event of the button and when I have a record in the subform, the record is deleted when I click the button. However, the main form's record is not deleted. Is there a way for me to write the code in such a way that when I click on it, both the subform and the main form's data will not be stored in the table?
Do you mean I click on the delete button twice? I've added my sample database and I hope that you will understand my scenario better now. When I first click on the button, the record in the subform is deleted but not the main form. Clicking the button again on the main form produces an error.
Hmm, it seems it won't work that way. However, you can do the following:
Add POID from tblOrderInfoMain to the query and place this field hidden on the form. Next, write a delete query where this POID field on the form will be used as a parameter.
In the code, after deleting the subform record, execute this delete query.
I just saw you checked only the update cascade, why not the delete cascade? You only need to delete the main record, and all the rest will be deleted.