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

error regarding Private Sub cmdDelete_Click()

143 100+
HI..
I need help over here... i have a delete button but is giving me error as " operation is not allowed when the object is closed"
Can anyone help me here, plz
thanks a lot


Private Sub cmdDelete_Click()
Dim X As String
Dim Rs As New ADODB.Recordset
If Rs.State = adStateOpen Then Rs.Close
'Rs.Open
X = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
If X = vbYes Then
Rs.Delete
Rs.Close
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"
End If
End Sub
Jun 30 '08 #1
6 1992
QVeen72
1,445 Expert 1GB
Hi,

You are Closing the recordset object. Recordset object has to be Open, to delete the Record

remove this line :If Rs.State = adStateOpen Then Rs.Close

Regards
Veena
Jun 30 '08 #2
squrel
143 100+
Hi Veena..
I removed tht line but stil i m getting the same error...
Jul 2 '08 #3
squrel
143 100+
Dear Veena,
i have changed my code to this...

Private Sub cmdDelete_Click()
Dim X As String
Dim RECORD As String
Dim Rs As New ADODB.Recordset
' Rs.Open
'Rs.Open ("select * from CASEMASTER where Id = '" & txtId.Text & "'"), Db, adOpenKeyset, adLockPessimistic
X = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
If X = vbYes Then
Rs.Open ("select * from CASEMASTER where Id = '" & txtId.Text & "'"), Db, adOpenKeyset
Rs.Delete
Rs.Close
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"
Call Grid_Data
End If
End Sub


the selected record is deleting for the first time but when i select another record is giving me this error " Either BOF or EOF is true, or the current record has been deleted".... and the second probelm is my gird is not gettind refreshed...
plz help
Jul 2 '08 #4
lotus18
866 512MB
Try this

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDelete_Click()
  2. Dim X As String
  3. Dim RECORD As String
  4. Dim Rs As New ADODB.Recordset
  5. X = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
  6. If X = vbYes Then
  7. Rs.Open ("Delete from CASEMASTER where Id = '" & txtId.Text & "'"), Db, adOpenKeyset
  8. Rs.Close
  9. Set Rs=Nothing
  10. MsgBox "Record Deleted!", , "Message"
  11. Call Grid_Data
  12. Else
  13. MsgBox "Record Not Deleted!", , "Message"
  14. Call Grid_Data
  15. End If
  16. End Sub
At line 7 and 8 instead of opening the recordset try the execute command
Expand|Select|Wrap|Line Numbers
  1. db.Execute "Delete from CASEMASTER where Id = '" & txtId.Text & "'"
I assume that your db is your active connection and take a look also at line 11 I added Call Grid_Data to refresh the list assuming that this is your subroutine to refresh the list.

Rey Sean
Jul 2 '08 #5
squrel
143 100+
Hi Lotus..
Thank u very much for ur help.. i did whtever u told me.. i m not getting any error bt the record is not getting deleted from the grid or database...
my code is this now :

Private Sub cmdDelete_Click()
Dim X As String
Dim RECORD As String
Dim Rs As New ADODB.Recordset
X = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
If X = vbYes Then
Db.Execute "Delete from CASEMASTER where Id = '" & txtId.Text & "'"
'Rs.Open ("Delete from CASEMASTER where Id = '" & txtId.Text & "'"), Db, adOpenKeyset
'Rs.Close
Set Rs = Nothing
MsgBox "Record Deleted!", , "Message"
Call Grid_Data
Else
MsgBox "Record Not Deleted!", , "Message"
Call Grid_Data
End If
End Sub

Need ur help here... Thankx
Jul 3 '08 #6
squrel
143 100+
I got it.. thankx a lot :)
Jul 3 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
3
by: Lorenc | last post by:
Is anybody experiencing the following error when trying to export a crystal report to a pdf? This error happens randomly. ------------------------------------------------------------------------...
1
by: sharmadeep1980 | last post by:
Hi All, I am facing a very unique problem while compling my project in "Release" build. The project is building in DEBUG mode but giving linking error on Release build. Here is the error:...
1
by: Akinyemi | last post by:
I created a Database which I named "Address". I went through the Control Panel and created a DSN to enable me connect to the Database through ODBC. I then created a Form with the same fields as...
2
by: arun1985 | last post by:
In the project i am using i am having the following code and when i upload it to the server.Its givig me the following error in the global.cs file. Server Error in '/' Application. ...
1
by: BSand0764 | last post by:
I'm getting an error that I can't seem to resolve. When I compile the Functor related logic in a test program, the files compile and execute properly (see Listing #1). However, when I...
1
by: THEAF | last post by:
i'm trying to create a reminder form, when i add a new reminder its ok but when i try to delete a reminder then i get No Current Record problem. Form Load Private Sub Form_Load() Dim s() As...
0
by: bssandeshbs | last post by:
I am developing a Address Book Database Project using Visual Basic 6... When i click the delete button the data does'nt get deleted in the FrontEnd ..But it gets deleted in Database when we see in...
3
by: graphicssl | last post by:
Okay, so first of all, I'm a designer first and a light coder second (I'm only really trained with HTML and CSS). So I apologize for having to post about something that's probably super-trivial! ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.