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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Record deletion problem 1

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I have a mainform and subform. They are both bound to related tables. On the subform I have a button to create a new record. However if after typing in data I change my mind and press an abort button it leaves a blank record in my child table.

I am using:

DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnings True

In the abort button.

I put two textboxes on the subform which display the primary keys of both tables. Before the record is created the first primary key shows the primary key of the mainform record I had selected, and the second textbox shows (autonumber). As soon as I start typing the second textbox shows the related child table being allocated a primary key, so far so good. However when I press the abort button, a new number appears in the second textbox, and if I hide the subform, and close the database from the now visible mainform I then find its left a blank record in the child table having the primary key value I last saw.

I have debugged to see if another command is made for a new record to be created after aborting but cannot find anything. Any ideas, thanks
 
Problem solved. One of the controls had an on exit event. This was getting fired after leaving it to click abort. It all went round in a circle so now I know where the problem is I can fix it. Thanks
 
ZOR,
You really should replace the DoMenuItem with RunCommand. The DoMenuItem is old, hard to read, and not maintained.


Ex:
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
versus the readable
DoCmd.Runcommand acCmdDeleteRecord
 
Many thanks. I will now use that in future.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top