does not delete record

D

deb

The below code does not delete the record if "yes" is selected.
What is wrong with this code?

Private Sub Form_Unload(Cancel As Integer)

If Me.M670 < Me.M070 Then

Msg = "M670 cannot be before M070." _
& vbCr & "If you close now, this Project will be DELETED." _
& vbCr & vbCr & "Do you want to close?"
ans = MsgBox(Msg, vbYesNo)

If ans = vbNo Then
MsgBox "Please, Select a M670 Date." _
& vbCr & "and make changes(as needed)"
Cancel = True

Else
Me.Undo
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If
End If
Exit Sub
End Sub
 
D

deb

This post was suppose to go into the forms area. I put in reports by accident.
maybe someone can answer anyway


thanks...
 
K

Klatuu

First item, the DoMenuItem code is obsolete and should not be used.
Second, since this code has been obsolete since '97, I have no idea what it
is trying to do.
Third, are you trying to delete the record from the table, or just from the
form?

Can you please explain what you want to do and maybe I can show you how.
 
D

daniel12k

This post was suppose to go into the forms area. I put in reports by accident.
maybe someone can answer anyway

thanks...
--
deb










- Show quoted text -

how can i delete a record from a form and have a report showing all
the deleted records?
 
J

John Spencer

Well, if you delete a record, it is impossible to have a report showing that
record.

In the delete section of the code, you need to test for whether or not the
record is a new record. If it is then Me.Undo should work to "clear" the
record. If the record is an existing saved record, then do you really want to
delete it or do you want to reset the record back to its original values? If
you don't want to delete it, then Me.Undo works again.

If you really do want to delete the record, then
DoCmd.RunCommand acCmdDeleteRecord
should delete the current record.

I'm not so sure that the UNLOAD event is the proper place to try any of this.
By that time the record has probably been saved, so it is probable that
Me.Undo won't do anything.

I would rather use the form's Before update event to make this decision. You
could set a form-level variable that could be read by the unload event to
cancel the unload event. You would have to reset the variable in the form's
current event so you could close the form.

John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
 
E

Evi

Although you can't print a report about something that doesn't exist any
more, you could set the form's Properties so that it does not allow
deletes, instead, using a custom button, you could run an Append query which
appends the record to an archive table then deletes it from the main table.
One of the fields in the Archive table should have a date Time field
formatted to show both date and time and having the Default Value as
Now()
so you can check which records were changed/deleted. Print off your report
before deleting the records from the Archive table.

Evi

PS If this works, have a go at answering my question in formscoding, it's
driving me batty!

how can i delete a record from a form and have a report showing all
the deleted records?
 
E

Evi

'Not finding EOF - 'no current Record' error' dated 04/05/08

As you'll see, I've chickened out of it, Chuck. It beat me!

Evi



 

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