Results 1 to 10 of 10

Thread: problem with delete operation

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    111

    Angry problem with delete operation

    Hi,
    I have the following code:
    VB Code:
    1. With Adodc1
    2. .RecordSource = "Select * from ATable where id = " & txtID.Text
    3. End With
    4.  
    5. Adodc1.Recordset.Delete
    6. Adodc1.Recordset.Requery
    7. Adodc1.Refresh

    The first time that this runs, everything is ok and the record is deleted. But the second time, when the user enters another txtID, meaning when the user wants to delete another record, then I get the following error:

    Run-time error '3012'
    Either BOF or EOF is True, or the current record has been deleted. Operation requires a current record.

    It is important to note, that after the first deletion OI clear the txtID text box. And also, that I check if EOF or BOF is True then I set Adodc1.Recordset.MoveFirst.

    What am I doing wrong? Can anyone enlight me pls?
    thx in advance

  2. #2
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: problem with delete operation

    where is the code for your complete sub.
    i dont see where you have checked for BOF/EOF

  3. #3
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: problem with delete operation

    you have to check whether your recordset returns any result or not...

    VB Code:
    1. If Not Adodc1.EOF Then
    2.     Adodc1.Recordset.Delete
    3.     Adodc1.Recordset.Requery
    4.     Adodc1.Refresh
    5. Else
    6.     MsgBox "No Records found !"
    7. End If
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    111

    Re: problem with delete operation

    Do I also have to check for .BOF???

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: problem with delete operation

    Quote Originally Posted by rasty1611
    Do I also have to check for .BOF???
    Maybe, maybe not.

    However, it wouldn't hurt and could only help.

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

    Re: problem with delete operation

    if Adodc1.Recordset.Recordcount > 0 ?????
    Adodc1.Recordset.movelast
    else
    ??? 'Record not found
    endif

  7. #7
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: problem with delete operation

    VB Code:
    1. If Not [HL]adodc1.BOF AND Not[/hl] Adodc1.EOF Then
    2.     Adodc1.Recordset.Delete
    3.     Adodc1.Recordset.Requery
    4.     Adodc1.Refresh
    5. Else
    6.     MsgBox "No Records found !"
    7. End If

  8. #8
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: problem with delete operation

    Quote Originally Posted by jethrobg
    if Adodc1.Recordset.Recordcount > 0 ?????
    Adodc1.Recordset.movelast
    else
    ??? 'Record not found
    endif
    This means that if you have more than 0 records, to start at the last record... do you want to do that?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    111

    Re: problem with delete operation

    ok.thank u all. I think now it is working...

  10. #10

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