Deleting a child record

G

Guest

I have two forms, an employee form and a test date subform.

I want to delete a test date in the subform, however, there is a link to the
test record in the employee form.

What I've tried so far is to clear the link the employee form. However, I'm
still prevented from deleting the test date record since the parent record is
not updated.


If Parent.LastTest = DLookup("TestID", "Test", "employeeID=" &
Parent.EmployeeID & _
" And LocationID=" & ctrl.Tag) Then
Parent.LastTest = Null

That part works, the field is cleared. However, the delete will not work
because record is not updated.

So, I tried the add the following:

Parent.update

However, I get the message: Run time error '2465'. Application defined or
object defined error.

So, I tried to be tricky and instead use the following:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

However, Access was not having it, and gave me the message:

Run time error '2046': The command or action 'SaveRecord' isn't available
now.


Does anyone have a work around? Thanks.
 
S

Steve Schapel

Leif,

When the focus moves to the subform, the parent form record should be
saved. There should be no need to do this explicitly. And normally the
fact that a child record is linked to a parent record should not prevent
the deletion of the child record via the subform. In other words,
what's the problem? Before you start clearing the value of the linking
field in the parent form, and you try to delete the subform record, what
happens?
 
G

Guest

Steve,

The user is deleting the record from the subform, so the focus is in the
subform. The data in the subform is actually information from a number of
records. The information is coming from a cross tab query.

Since you cannot change or delete data from a cross tab query, I had to be a
bit creative. I use the fields after_update event to locate and update and
underlining record. This works great is the user is only updating the
subform value (which is a date). Also it works great if the user wants to
delete a record from the subform (if the user deletes the entire content of
the subform cell I ask if he wants a delete). However, one of the cells in
the subform shows the last test date. This is also shown in the parent form.
This referential integrity stops that record from being deleted because the
employee form is referencing it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top