Results 1 to 13 of 13

Thread: [RESOLVED] delete data

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Resolved [RESOLVED] delete data

    Private Sub Command1_Click()
    VB Code:
    1. Dim objConn As ADODB.Connection
    2. Set objConn = New ADODB.Connection
    3. objConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False")
    4. Dim x As String
    5. dim rs1 as adodb.recordset
    6. Set rs1 = New ADODB.Recordset
    7.  
    8. x = " delete from data where inv ='" & Form29.Text1 & "'"
    9. rs1.Open x, objConn
    10. If rs1.EOF Then
    11. MsgBox ("INVOICE NOT FOUND")
    12. Else
    13. MsgBox ("INVOICE DELETED")
    14. Form30.Visible = False
    15. End If
    16. End Sub


    when i run the above coe it gives error at line rs1.eof.. that operation can not be done when object is closed
    tell me what is the problem

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: delete data

    VB Code:
    1. Public con As New ADODB.Connection
    2. Function Open_Connection()
    3. If Con.State = 1 Then
    4.     Con.Close
    5. End If
    6. With Con
    7.     .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False"
    8.     .ConnectionTimeout = 30
    9.     .CursorLocation = adUseClient
    10.     .Open
    11. End With
    call this function on the form load

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Re: delete data

    still not working same problem

  4. #4
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: delete data

    VB Code:
    1. Public Con As New ADODB.Connection
    2.  
    3. Private Sub Command1_Click()
    4. Dim Rs1 As New ADODB.Recordset
    5. X = "delete from data where inv ='" & Form29.Text1.Text & "'"
    6. Rs1.Open X, Con, adOpenDynamic, adLockOptimistic
    7. If Rs1.EOF = True Then
    8. MsgBox ("INVOICE NOT FOUND")
    9. Else
    10. MsgBox ("INVOICE DELETED")
    11. Form30.Visible = False
    12. End If
    13. End Sub
    14.  
    15. Private Sub Form_Load()
    16. 'Function Open_Connection()
    17. If Con.State = 1 Then
    18.     Con.Close
    19. End If
    20. With Con
    21.     .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False"
    22.     .ConnectionTimeout = 30
    23.     .CursorLocation = adUseClient
    24.     .Open
    25. End With
    26. End Sub
    As i understand your problem post in this which line error is occuring

  5. #5
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: delete data

    What about....

    VB Code:
    1. Dim strCn As String
    2. strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False"
    3.  
    4. Dim x As String
    5. Dim rs1 = New ADODB.Recordset
    6.  
    7. x = "delete from data where inv ='" & Form29.Text1 & "'"
    8.  
    9. rs1.Open x, strCn, adOpenStatic, adLockOptimistic
    10.  
    11. If rs1.EOF Then
    12. MsgBox ("INVOICE NOT FOUND")
    13. Else
    14. MsgBox ("INVOICE DELETED")
    15. Form30.Visible = False
    16. End If
    17. End Sub

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Re: delete data

    VB Code:
    1. If Rs1.EOF = True Then
    this line is highlighted as the error comes saying the operation can not be performed when the object is closed

  7. #7
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: delete data

    VB Code:
    1. Public Con As New ADODB.Connection
    2. Dim TSQL As String
    3. Public RTMP As New ADODB.Recordset
    4.  
    5. Private Sub Command1_Click()
    6. TSQL = "delete from data where inv ='" & Form29.Text1.Text & "'"
    7. Set RTMP = Get_Special_Record_Set(TSQL)
    8. If RTMP.EOF = True Then
    9. MsgBox ("INVOICE NOT FOUND")
    10. Else
    11. MsgBox ("INVOICE DELETED")
    12. Form30.Visible = False
    13. End If
    14. End Sub
    15.  
    16. Private Sub Form_Load()
    17. Function Open_Connection()
    18. If Con.State = 1 Then
    19.     Con.Close
    20. End If
    21. With Con
    22.     .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False"
    23.     .ConnectionTimeout = 30
    24.     .CursorLocation = adUseClient
    25.     .Open
    26. End With
    27. End Function
    28.  
    29. Function Get_Special_Record_Set(ByRef Shakti As String) As ADODB.Recordset
    30. Dim Shakti As String
    31. If RTMP.State = 1 Then
    32. RTMP.Close
    33. End If
    34. RTMP.Open Shakti, Con, adOpenDynamic, adLockOptimistic
    35. Set Get_Special_Record_Set = RTMP
    36. End Function
    Please check this quesry that it is correct or not
    TSQL = "delete from data where inv ='" & Form29.Text1.Text & "'"

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Re: delete data

    it is actually deleting the record from the database even after giving the error that means query is ok

  9. #9
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: delete data

    Quote Originally Posted by elixir_5000
    it is actually deleting the record from the database even after giving the error that means query is ok
    r u getting error still

  10. #10
    New Member
    Join Date
    Dec 2005
    Posts
    8

    Re: delete data

    VB Code:
    1. objConn.Execute "delete [B]what?? *[/B] from data where inv ='" & Form29.Text1 & "'
    try this

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Re: delete data

    yes still there is the same error

  12. #12
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: delete data

    VB Code:
    1. Private Sub Command1_Click()
    2. TSQL = "select * from data where inv ='" & Form29.Text1.Text & "'"
    3. Set RTMP = Get_Special_Record_Set(TSQL)
    4. If RTMP.EOF = True And RTMP.BOF = True Then MsgBox ("INVOICE NOT FOUND"): Exit Sub
    5. While Not RTMP.EOF
    6.     RTMP.Delete
    7.     RTMP.MoveNext
    8. Wend
    9. MsgBox ("INVOICE DELETED")
    10. Form30.Visible = False
    11. End Sub

    Try this final code

  13. #13
    New Member
    Join Date
    Dec 2005
    Posts
    8

    Re: delete data

    VB Code:
    1. Dim objConn As ADODB.Connection
    2. Set objConn = New ADODB.Connection
    3. objConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False")
    4. Dim x As String
    5. dim rs1 as adodb.recordset
    6. Set rs1 = New ADODB.Recordset
    7.  
    8. x = " select * from data where inv ='" & trim(Form29.Text1) & "'"
    9. rs1.open x,objConn
    10. if rs1.recordcount>0 then
    11.  rs1.close
    12.  objConn.execute("delete * from data where inv ='" & Form29.Text1 & "')
    13.  msgbox "record deleted
    14. else
    15.  rs.close
    16.  msgbox "item not found"
    17. endif

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width