By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,118 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,118 IT Pros & Developers. It's quick & easy.

error regarding Private Sub cmdDelete_Click()

100+
P: 143
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
Share this Question
Share on Google+
6 Replies


QVeen72
Expert 100+
P: 1,445
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

100+
P: 143
Hi Veena..
I removed tht line but stil i m getting the same error...
Jul 2 '08 #3

100+
P: 143
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
100+
P: 866
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

100+
P: 143
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

100+
P: 143
I got it.. thankx a lot :)
Jul 3 '08 #7

Post your reply

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