Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting the current record with Form's On Close event

Status
Not open for further replies.

Nevermoor

Programmer
Jul 25, 2003
218
US
Hi,

I have a form that uses dynamic default values (form's values are all entered based on the last record's values). There is only one drawback though, the form will automatically fill out the record after the last one entered thus creating a duplicate value.

I have appropriate markers to make sure that only duplicate records are deleted, but the normal deleting code won't work in the On Close event. The error says:

"Run-time error '2046'
"The command or action 'SelectRecord' isn't available now."

The Code I tried is:

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
 
That generates the same error.

I have no idea why these commands aren't available during On Close, but they don't seem to be
 
That brings up the same error

I have no idea why these commands aren't available during the On Close event, but they just don't seem to be.
 
It seems that, when it's told to close, it doesn't keep track of the current record anymore. I set up a msgbox in OnClose to tell the values of a couple records. It would give the values from the first record rather than what was the current record.

Thus, I can think of a couple alternatives.

1) Use a recordset object to open the source of the form, find the duplicate, and delete it. This does not involve the form, so closing shouldn't affect it.

2) Force users to use a command button to close. Put in the delete commands before closing the form.
 
2) Force users to use a command button to close. Put in the delete commands before closing the form.

Had to use the same method.
 
Thanks guys!

too bad it has to work that way though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top