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

Signature
deb
deb - 17 Apr 2008 16:26 GMT
This post was suppose to go into the forms area. I put in reports by accident.
maybe someone can answer anyway
thanks...

Signature
deb
> The below code does not delete the record if "yes" is selected.
> What is wrong with this code?
[quoted text clipped - 21 lines]
> Exit Sub
> End Sub
daniel12k@googlemail.com - 28 Apr 2008 16:06 GMT
> This post was suppose to go into the forms area. I put in reports by accident.
> maybe someone can answer anyway
[quoted text clipped - 33 lines]
>
> - Show quoted text -
how can i delete a record from a form and have a report showing all
the deleted records?
John Spencer - 28 Apr 2008 16:58 GMT
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
>> This post was suppose to go into the forms area. I put in reports by accident.
>> maybe someone can answer anyway
[quoted text clipped - 29 lines]
> how can i delete a record from a form and have a report showing all
> the deleted records?
Evi - 04 May 2008 14:29 GMT
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!
<daniel12k@googlemail.com> wrote in message
how can i delete a record from a form and have a report showing all
the deleted records?
Chuck - 05 May 2008 13:21 GMT
Big snip
>Evi
>
>PS If this works, have a go at answering my question in formscoding, it's
>driving me batty!
What are the date and heading?
Chuck
Evi - 05 May 2008 14:27 GMT
'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
> Big snip
> >Evi
[quoted text clipped - 4 lines]
> What are the date and heading?
> Chuck
Klatuu - 17 Apr 2008 20:21 GMT
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.

Signature
Dave Hargis, Microsoft Access MVP
> The below code does not delete the record if "yes" is selected.
> What is wrong with this code?
[quoted text clipped - 21 lines]
> Exit Sub
> End Sub