Results 1 to 3 of 3

Thread: refresh after SQL Delete statement

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    54

    refresh after SQL Delete statement

    I'm writing code In vb and when I run this code it says it cant refresh because the object is not open. When I put in "Adodc1.RecordSet.Open" it works perfectly the first time.
    But If i run the function again, I get an error saying it cant open the recordset cause its already open.

    I've tried putting adodc1.recordset.close, right before the function ends figuring that i'd be ok, but alas that didn't work either. Is there any way I can check to see if the recordset is already open?

    I would really appreciate the help.. Thanks in Advance.


    IF Adodc1.Recordset.RecordCount > 0 THEN

    Adodc1.RecordSource = "DELETE FROM EquipOut WHERE Sequence = " & SeqNum
    Adodc1.Refresh
    MsgBox "DELETED SeqNum"

    END IF

  2. #2
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    FL
    Posts
    258
    Your problem is probably because you are using the RecordSource property to delete records. You are replacing whatever you used to get the records to begin with when you say ...
    Adodc1.RecordSource = "DELETE FROM EquipOut WHERE Sequence = " & SeqNum

    now you try and refresh, but Adodc1 thinks its record source is "DELETE FROM EquipOut WHERE Sequence = " & SeqNum

    You can use the Connection or Command Objects Execute Method to issue SQL commands to the DB.

    Or you can delete the record from the Recordset and then refresh...

    VB Code:
    1. If Adodc1.Recordset.RecordCount > 0 THEN
    2.  
    3. Adodc1.Recordset.MoveFirst
    4. Adodc1.RecordSet.Find "Sequence = " & SeqNum
    5. Adodc1.Recordset.Delete
    6. Adodc1.Refresh
    7. MsgBox "DELETED SeqNum"
    8. End If

    You need to have an updateable Recordset to do this.
    Last edited by mdake; Aug 21st, 2001 at 03:47 PM.

  3. #3
    Lively Member Rockman's Avatar
    Join Date
    Apr 2001
    Posts
    66
    To determine if a recordset is open or not, use the .State property of the recordset.

    hth

    - Jeff

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