A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

delete button in a form



 
 
Thread Tools Display Modes
  #1  
Old October 3rd, 2007, 08:10 AM posted to microsoft.public.access.forms
00 Michael Jordan
external usenet poster
 
Posts: 5
Default delete button in a form

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.


  #2  
Old October 3rd, 2007, 11:50 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default delete button in a form

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.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

" 00 Michael Jordan" wrote in message
...
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.


  #3  
Old October 3rd, 2007, 12:03 PM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default delete button in a form

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.

00 Michael Jordan wrote:
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.


--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via http://www.accessmonster.com

  #4  
Old October 4th, 2007, 02:02 AM posted to microsoft.public.access.forms
00 Michael Jordan
external usenet poster
 
Posts: 5
Default delete button in a form

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.

"Allen Browne" wrote in message
...
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.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

" 00 Michael Jordan" wrote in message
...
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.




  #5  
Old October 4th, 2007, 02:13 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default delete button in a form

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.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

" 00 Michael Jordan" wrote in message
...
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.

"Allen Browne" wrote in message
...
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.

" 00 Michael Jordan" wrote in message
...
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.


  #6  
Old October 4th, 2007, 04:25 AM posted to microsoft.public.access.forms
00 Michael Jordan
external usenet poster
 
Posts: 5
Default delete button in a form

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.



"Linq Adams via AccessMonster.com" u28780@uwe wrote in message
news:79227467cc451@uwe...
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.

00 Michael Jordan wrote:
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.


--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via http://www.accessmonster.com



  #7  
Old October 4th, 2007, 04:37 AM posted to microsoft.public.access.forms
00 Michael Jordan
external usenet poster
 
Posts: 5
Default delete button in a form

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

" 00 Michael Jordan" wrote in message
...
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.



"Linq Adams via AccessMonster.com" u28780@uwe wrote in message
news:79227467cc451@uwe...
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.

00 Michael Jordan wrote:
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.


--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via http://www.accessmonster.com





  #8  
Old October 4th, 2007, 04:54 AM posted to microsoft.public.access.forms
00 Michael Jordan
external usenet poster
 
Posts: 5
Default delete button in a form

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.



" 00 Michael Jordan" wrote in message
...
I figured out this problem only happens when I delete the last record. Any
help? Thanks.

" 00 Michael Jordan" wrote in message
...
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.



"Linq Adams via AccessMonster.com" u28780@uwe wrote in message
news:79227467cc451@uwe...
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.

00 Michael Jordan wrote:
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.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via http://www.accessmonster.com







 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:09 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.