We help IT Professionals succeed at work.

Access 2007 - Prompt and Error while deleting a record

SheahaST
SheahaST asked
on
1,561 Views
Last Modified: 2013-11-28
I have a split database. I have a button on a form bound to table (tblCalls).  The intent of this button is to delete the current record.   I am using the following code in the OnClick event to do this deletion:

            SQL = "DELETE * FROM tblCalls WHERE ID = " & Me.ID
            DoCmd.RunSQL SQL

This comes back with the following warning: "You are about to delete 1 row(s) from the specified table".  This is correct, but I would like this question to not appear.  How do you do this?  In Access Options/Advanced I unchecked the Confirm/Document Deletions check box, but that didn't do anything.

If I answer Yes to the above question, I get the following error message "can't delete 0 record(s) in the delete query due to key violations and 1 record(s) due to lock violations.
Selecting Yes to this message is suppose to run the query.  The record is not deleted.  There are no other records associated with this parent record.  I have set "Cascade Delete Related Records" to TRUE.

I have set "Record Locks" on the form to "Edited Record".   The record was not edited. I tried moving to another record with the following code:

            Dim iCurrentID
            iCurrentID = Me.ID
           
            ' Move away from current record so it can be deleted
            DoCmd.GoToRecord acDataTable, "tblCalls", acNext
           
            ' Delete Call - This record must exist
            SQL = "DELETE * FROM tblCalls WHERE ID = " & iCurrentID
            DoCmd.RunSQL SQL

 I get the error "GoToRecord isn't available now".  What does this error message mean?

Thanks for your help

Steve
Comment
Watch Question

CERTIFIED EXPERT

Commented:
Docmd.setwarnings False

....delete your records

Docmd.setwarnings True

Author

Commented:
Thank you.  The above does get rid of the warnings, but the code still does not delete the current record.  Any answers for the rest of my problem?

Author

Commented:
Setting the form's Record Locks to "No Locks" and then deleting the record with the above SQL command appears to delete the record from the table but not from the form.  Navigating back and forth gives a "Deleted Record" error, and eventually I reach a reference to a field in the deleted record.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you very much harfang.  Not only for the solution but for clarifying in my head the differences between a recordset and a table.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.