473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Unable to Delete a Record

I have a command button on a form that is supposed to Delete the record
being displayed. The record is displayed one to a form. The form is
not a Pop-Up nor is it Modal. Tracing the btnDelete event routine shows
that AllowDeletions is TRUE.

When the Delete button is clicked (without TRACE ON), I get a 'beep',
the recordselector (vertical bar on left of form) gets dark in color,
but the record is not deleted. Also, there is no error message that
pops up.

HOWEVER, when I trace the routine ...

Private Sub btnDelete_Click()
On Error GoTo Err_btnDelete_Click

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

Exit_btnDelete_Click:
Exit Sub

Err_btnDelete_Click:
Call ShowError("frmPeople", "btnDelete_Click", Err.Number,
Err.Description)
Resume Exit_btnDelete_Click

End Sub

When the first DoCmd is executed I get an error that displays from the
error displaying routine ShowError. The error says:

"The command or action 'Select Record' isn't available now"

I've looked around in the database options to see if I have something
set somewhere to prevent Deletions. I can't find anything.

This error happens for two tables using different forms, but the same
logic structure (delete command button with the same DoCmd
instructions).

HELP. I thought that I was so close to finishing this project. Now I'm
stumped again.

Thanks.

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #1
4 7818
Try replacing your 2 lines with:
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If

What this does is to undo any edits in progress: an undo or save has to
happen before the delete. If you are at a new record, that's all you need;
otherwise it executes the delete. This assumes the button is in the same
form as the record you want to delete. (If not, you can use the Delete
method on the RecordsetClone of that form, after setting the Bookmark to the
desired record.)

That should work, and generate an error if there is any reason why the
record cannot be deleted.

With your original code, the issue when tracing is probably that the VBA
window has focus when the 2nd DoMenuItem was executed. DoMenuItem applies to
the active window, and it can't delete a record out of the VBA window.

--
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.

"Susan Bricker" <sl*****@verizon.net> wrote in message
news:nH***************@news.uswest.net...
I have a command button on a form that is supposed to Delete the record
being displayed. The record is displayed one to a form. The form is
not a Pop-Up nor is it Modal. Tracing the btnDelete event routine shows
that AllowDeletions is TRUE.

When the Delete button is clicked (without TRACE ON), I get a 'beep',
the recordselector (vertical bar on left of form) gets dark in color,
but the record is not deleted. Also, there is no error message that
pops up.

HOWEVER, when I trace the routine ...

Private Sub btnDelete_Click()
On Error GoTo Err_btnDelete_Click

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

Exit_btnDelete_Click:
Exit Sub

Err_btnDelete_Click:
Call ShowError("frmPeople", "btnDelete_Click", Err.Number,
Err.Description)
Resume Exit_btnDelete_Click

End Sub

When the first DoCmd is executed I get an error that displays from the
error displaying routine ShowError. The error says:

"The command or action 'Select Record' isn't available now"

I've looked around in the database options to see if I have something
set somewhere to prevent Deletions. I can't find anything.

This error happens for two tables using different forms, but the same
logic structure (delete command button with the same DoCmd
instructions).

HELP. I thought that I was so close to finishing this project. Now I'm
stumped again.

Thanks.

Regards,
SueB

Nov 13 '05 #2
Allen,
Thank you for your suggestion. I'm getting closer.

Your suggestion seems to work, but it doesn't. Here's what happens now.

1. Click on Delete button
2. Get "canned" error msg: "You are about to delete 1 record(s). If you
click yes, you won't be able to undo the Delete operation. Are you sure
you want to delete these records?
3. Click Yes button.
4. NO additional pop-up message appears telling me that the record has
been deleted. However, I have some logic (in Form_Current()) to display
which record is being displayed out of how many records total. This
label is updated to reflect the record being deleted and the record
being displayed is changed to the next record (I think it's the next
record - didn't really check this).
5. Ok ... you think it worked. However, I have an unbound combobox used
to search for a record at the top of the screen. I make sure that it
has been requeried (after the delete) and it still has the original
record listed. When I close the form and go the previous form, where
there is a search combobox for this table, it still shows the record).
If I close the database and go back in, and repeat the entire logic
path, the record still exists and gets displayed when selected.

OK ... now the fun ...
When I trace the btnDelete_Click routine ...
on the actual delete command (from your suggestion) I get the following
error (which didn't appear when not tracing):
"The command or action 'DeleteRecord' isn't available now" (error number
2046).

Looks like the same problem as before.

Have another idea?
Thanks.
Regards,
SueB

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #3
Here's another way to delete the record in the form:
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
With Me.RecordsetClone
.Bookmark = Me.Bookmark
.Delete
End With
End If

You may want to add a confirmation dialog, as this won't automatically give
one.

It should work even if you trace through it, as it does not depend on the
form having focus.

If that also fails to delete the record, then something else is going on.

--
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.

"Susan Bricker" <sl*****@verizon.net> wrote in message
news:0K***************@news.uswest.net...
Allen,
Thank you for your suggestion. I'm getting closer.

Your suggestion seems to work, but it doesn't. Here's what happens now.

1. Click on Delete button
2. Get "canned" error msg: "You are about to delete 1 record(s). If you
click yes, you won't be able to undo the Delete operation. Are you sure
you want to delete these records?
3. Click Yes button.
4. NO additional pop-up message appears telling me that the record has
been deleted. However, I have some logic (in Form_Current()) to display
which record is being displayed out of how many records total. This
label is updated to reflect the record being deleted and the record
being displayed is changed to the next record (I think it's the next
record - didn't really check this).
5. Ok ... you think it worked. However, I have an unbound combobox used
to search for a record at the top of the screen. I make sure that it
has been requeried (after the delete) and it still has the original
record listed. When I close the form and go the previous form, where
there is a search combobox for this table, it still shows the record).
If I close the database and go back in, and repeat the entire logic
path, the record still exists and gets displayed when selected.

OK ... now the fun ...
When I trace the btnDelete_Click routine ...
on the actual delete command (from your suggestion) I get the following
error (which didn't appear when not tracing):
"The command or action 'DeleteRecord' isn't available now" (error number
2046).

Looks like the same problem as before.

Have another idea?
Thanks.
Regards,
SueB

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***

Nov 13 '05 #4
Allen,

Thanks, again, for trying to help. It didn't do the trick, though.
Looks like I have something else going on. I'll plug away at it and if
I find out I'll respond to this email thread. Boy am I stumped ... and
of course it's at the very worst time - just closed on a new house,
selling current house, trying to finish this project, and my REAL job's
responsibilities are falling to the wayside. ARGHHHH!!!

Regards,
SueB

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Barbara | last post by:
Hi, I have an sql database that has the primary key set to three fields, but has not been set as unique(I didn't create the table). I have 1 record that has 2 duplicates and I am unable to delete...
8
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: ...
3
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to...
7
by: travlintom | last post by:
Hi. I'm new to VB.net and am used to working with recordsets (much easier). I have a datagrid that, when the user double clicks on a row, I am giving them a chance to delete it. I thought this...
0
by: peterlewis | last post by:
Hi, I am unable to delete the current record from bindingnavigator - has a null bindingSource.Current although I can insert new records. The bindingnavigator was added as a control and the data...
2
by: mathewgk80 | last post by:
Hi all, i got an error "System.NotSupportedException: Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified" when i try to delete a row.. the code is...
1
by: Markw | last post by:
Hi folks I think I've got a variable problem but not 100% sure. Background: I took the CMS example from chapter 6 in "Build your Own Database Driven Website Using PHP&MySQL" and have attempted to...
3
by: Constantine AI | last post by:
Hi i am trying to DELETE a Record if the details do not exist within a table. Here is my code below; Dim strSQL As String Dim strSQL2 As String Dim Reply As String Dim db As...
8
by: harryjohal | last post by:
<?php $host="localhost"; $username="user"; $password="rmypwd"; $db_name="mydb"; $tbl_name="articles"; $cmd=$_GET; $id=$_GET;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.