Yet another beginner that cannot delete record in a half filled fo

Yet another beginner that cannot delete record in a half filled fo

Post by UmljaGFyZC » Thu, 17 Mar 2005 17:39:03


Hi there, no matter how many things I try, I cannot delete a record if the
form is only half filled out. On my main form I have a combo box that the
user can select a company, there is then a subform that shows all of that
companies contacts. I then have another form that is opened from a button.
This form is used to add a contact, once the form is completed they can save
the record and this requeries the subfrom to show the new contact. However if
the user decides that they do not want to add a contact, I want them to be
able to exit the form without updating the records associated with that
company. I have a button - but it does not work. When I click it, it clears
the information and just puts in a blank record. The code is as follows -

'Delete the Record halfway through filling out the form and requery main form

Private Sub cmdExit_Click()
If MsgBox("Delete the current record are you sure?", _
vbYesNo + vbExclamation + vbDefaultButton2, _
"Please Confirm") = vbYes Then
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close
Forms!frmmain!sfrmImage2.Form!.Requery
End If
End Sub

Any ideas where I am going wrong?

Thanks in advance

Richard
 
 
 

Yet another beginner that cannot delete record in a half filled fo

Post by TWFydml » Thu, 17 Mar 2005 23:25:02

Here are a few suggestions:
1. You may want to try "Cancel = True" and/or "Me=Undo" in the BeforeUpdate
event of the form
2. If you are using an ADO connection, you can try using BeginTrans,
CommitTrans, and Rollback
3. If the first two don't work, perhaps you can get the ID of the new record
when it is created, then do: Docmd.RunSQL "delete * from YourTable where ID =
" & TheIDOfTheNewRecord & ";"

Hope that helps.

Marvin