Deleting Record Problems

  • Thread starter Thread starter Eddy
  • Start date Start date
E

Eddy

I'm using the following code to delete a record from a form in Access97.

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

The problem is after the record deletes, the Navigation Buttons at the
bottom of the screen still
shows the record as being the one deleted. For example, if I am adding a
line 2 to the record, after deleting line 2, the Navigation Button still
says 2 while the line number field says 1. If I try to leave the form I get
the message that the changes will not take effect because of duplicate
records in Key fields. Is there a way to call up the privious line after
deleting the line to avoid this error? Or am I missing something?

Thanks for the help.
 
Eddy said:
I'm using the following code to delete a record from a form in Access97.

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

The problem is after the record deletes, the Navigation Buttons at the
bottom of the screen still
shows the record as being the one deleted. For example, if I am adding a
line 2 to the record, after deleting line 2, the Navigation Button still
says 2 while the line number field says 1. If I try to leave the form I get
the message that the changes will not take effect because of duplicate
records in Key fields. Is there a way to call up the privious line after
deleting the line to avoid this error? Or am I missing something?

Try this after the above lines (assuming they are executed in the
form's own module):

Me.Requery

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
Eddy said:
I'm using the following code to delete a record from a form in
Access97.

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

The problem is after the record deletes, the Navigation Buttons at the
bottom of the screen still
shows the record as being the one deleted. For example, if I am
adding a line 2 to the record, after deleting line 2, the Navigation
Button still says 2 while the line number field says 1. If I try to
leave the form I get the message that the changes will not take
effect because of duplicate records in Key fields. Is there a way to
call up the privious line after deleting the line to avoid this
error? Or am I missing something?

Thanks for the help.

I'm a little confused: what "line number field"? how do you get a
duplicate-key error when deleting a record?

I wouldn't use the lousy code written by the command-button wizard in
the first place. Try this instead:

If Me.Dirty Then Me.Undo

If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If

I'm not sure whether the line-number business you report is abnormal
behavior or expected. Bear in mind that if you're on the last record in
the form, record 10 out of 10 for example, and you delete that record,
you're now going to be on the "new record", which will also be listed as
record 10 out of 10, in anticipation that you will enter something here
and save it. That's the way the built-in navigation controls work.
 
Back
Top