473,385 Members | 1,863 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,385 software developers and data experts.

Sometimes another record gets deleted !

Below is my code to delete a record in a continuous form. I can't
figure out any reason but sometimes (another) record gets deleted
instead of where the record pointer is positioned.

Small table - just 750 records ... no primary key defined.

Using Access 2003 under WinXP SP1.

There must be something I've overlooked. Maybe one of you gurus could
help.

Thks & Best Rgds,
Prakash.
--- Code snippet begins here ---------------------------
Private Sub Cmd_Delete_Click()
On Error GoTo Err_Cmd_Delete_Click

Dim choice As Long
Dim msg As String
msg = "Delete Contact: " & Me.Contact_person & " ?" & Chr(13) &
Chr(13) & "This Action Cannot Be Undone !"
choice = MsgBox(msg, vbYesNo + vbQuestion, "Delete Record")
If choice = vbYes Then
On Error Resume Next
DoCmd.RunCommand acCmdUndo 'Undo the changes if the
user has edited the record ... REQUIRED ! DO NOT DELETE THIS !
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord 'Delete the record
DoCmd.SetWarnings True

Me.Cmb_Company.Requery
Me.Cmb_ContactPerson.Requery
End If

Exit_Cmd_Delete_Click:
Exit Sub

Err_Cmd_Delete_Click:
MsgBox Err.Description
Resume Exit_Cmd_Delete_Click

End Sub
--- Code snippet ends here ----------------------------------

Nov 13 '05 #1
3 1528
On 7 Dec 2004 10:29:48 -0800, "Prakash" <si****@omantel.net.om> wrote:

No primary key???? Add one!

-Tom.

Below is my code to delete a record in a continuous form. I can't
figure out any reason but sometimes (another) record gets deleted
instead of where the record pointer is positioned.

Small table - just 750 records ... no primary key defined.

Using Access 2003 under WinXP SP1.

There must be something I've overlooked. Maybe one of you gurus could
help.

Thks & Best Rgds,
Prakash.
--- Code snippet begins here ---------------------------
Private Sub Cmd_Delete_Click()
On Error GoTo Err_Cmd_Delete_Click

Dim choice As Long
Dim msg As String
msg = "Delete Contact: " & Me.Contact_person & " ?" & Chr(13) &
Chr(13) & "This Action Cannot Be Undone !"
choice = MsgBox(msg, vbYesNo + vbQuestion, "Delete Record")
If choice = vbYes Then
On Error Resume Next
DoCmd.RunCommand acCmdUndo 'Undo the changes if the
user has edited the record ... REQUIRED ! DO NOT DELETE THIS !
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord 'Delete the record
DoCmd.SetWarnings True

Me.Cmb_Company.Requery
Me.Cmb_ContactPerson.Requery
End If

Exit_Cmd_Delete_Click:
Exit Sub

Err_Cmd_Delete_Click:
MsgBox Err.Description
Resume Exit_Cmd_Delete_Click

End Sub
--- Code snippet ends here ----------------------------------


Nov 13 '05 #2
Prakash wrote:
Below is my code to delete a record in a continuous form. I can't
figure out any reason but sometimes (another) record gets deleted
instead of where the record pointer is positioned.

Small table - just 750 records ... no primary key defined.

Using Access 2003 under WinXP SP1.

There must be something I've overlooked. Maybe one of you gurus could
help.

Thks & Best Rgds,
Prakash.
--- Code snippet begins here ---------------------------
Private Sub Cmd_Delete_Click()
On Error GoTo Err_Cmd_Delete_Click

Dim choice As Long
Dim msg As String
msg = "Delete Contact: " & Me.Contact_person & " ?" & Chr(13) &
Chr(13) & "This Action Cannot Be Undone !"
choice = MsgBox(msg, vbYesNo + vbQuestion, "Delete Record")
If choice = vbYes Then
On Error Resume Next
DoCmd.RunCommand acCmdUndo 'Undo the changes if the
user has edited the record ... REQUIRED ! DO NOT DELETE THIS !
What is the Undo for? Who cares if the data has been modified? What if
this is a new record and you tell it to Undo? What record gets deleted
then? Certainly not a new, unsaved record.

You could put in something like
If not Me.NewRecord then
...delete code
Else
Me.Undo
Endif

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord 'Delete the record
DoCmd.SetWarnings True

Me.Cmb_Company.Requery
Me.Cmb_ContactPerson.Requery
End If

Exit_Cmd_Delete_Click:
Exit Sub

Err_Cmd_Delete_Click:
MsgBox Err.Description
Resume Exit_Cmd_Delete_Click

End Sub
--- Code snippet ends here ----------------------------------

Nov 13 '05 #3
It's just a simple address book. I'd have to use something like an
autonumber field to add a primary key and personally I'm not a fan of
autonumbers.

Moreover, a primary key does not seem to be required here as i would'nt
serve any purpose.

In light of all this would you still recommend me ading a primary key
...and..
Do you think it'll help solve my problem of another record getting
deleted ?

Thx & Best Rgds,
Prakash.

Nov 13 '05 #4

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

Similar topics

3
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
0
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
4
by: Susan Bricker | last post by:
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...
5
by: prakashwadhwani | last post by:
The Delete Event/Proc & "Save_Fields_In_Form_Header" Event/Proc in my form were working perfectly. However, after I added a call to the "Save_Fields_In_Form_Header" Event/Proc in the...
3
by: marcf | last post by:
Hi Everyone, Hopefully someone will be able to offer a suggestion to this problem. I have a multi user CMS running at work which I wrote. Aside from a few bugs everything has been going fine...
6
BeemerBiker
by: BeemerBiker | last post by:
I can't get rid of a "deleted" record in a database. Even if I delete it the record shows back up the next time I do an update. The following code generates an error message when using...
1
by: CoreyReynolds | last post by:
Hello, I have attached a picture of my Access form. Each record has a delete button beside it, pressing it deletes the record and cascades to the child records. Horray. Except sometimes, for a...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.