delete button in a form

  • Thread starter 00 Michael Jordan
  • Start date
0

00 Michael Jordan

I got 3 records in a table and I have a form where the source is based on
this table. Now I created a delete button from toolbox wizard and it should
delete the current record. If I press that button, the current record on
the form is empty out instead of deleted. After deletion, there are 3
records and 1 is all empty. How can I make it deleting a record instead of
empty out the record? I am running access 97. Please help. Thanks.
 
A

Allen Browne

Try this code instead of what the wizard wrote:
If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then RunCommand acCmdDeleteRecord

Note that the 3rd record could be the "new record" row of the form. If so,
it will show "Record 2 of 2" when you move back to the previous one.
 
L

Linq Adams via AccessMonster.com

If the record is "emptied out" then it had been deleted! An "empty" record on
a form is actually a new record, awaiting data! If you delete a record from a
form, by default Access moves on and displays the next record in order.If the
record deleted is the last record in the displayed recordset, which I expect
it is in your case, Access still moves on to display the next "record" which
in this case is a new or blank record. If you prefer some other behavior,
you'll have to add that to your button's deetion code. Me.Requery, for
ewxample,will take you to and display the first record.
 
0

00 Michael Jordan

I tried the code but still the same. I still got 3 got records with one
empty records and after refresh, the empty record goes to the first record.
 
A

Allen Browne

In that case, you will need to delete that empty record from your table,
and/or figure out what is causing it to be created all the time.
 
0

00 Michael Jordan

I added me.requery at the end of code. After I press the delete button, the
empty record is shown in the form and when I try to go to previous record,
it gives me a msg window as following:

Update or CancalUpdate without AddNew or Edit.

After I click the OK button, it stayed in the same form and I am stucked.
Please help. Thanks.
 
0

00 Michael Jordan

I figured out this problem only happens when I delete the last record. Any
help? Thanks.
 
0

00 Michael Jordan

I have worked around the problem. By adding the following code to load form
event:

Me.AllowAdditions = False

and set it to right for unload form event.
 

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