Is this a BUG of M$? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Is this a BUG of M$?

First,Create tst.mdb on drive D,then create a table named Table1,insert some data。Why it ONLY deletes 2 record? not all of them? Thanks a lot!

Option Explicit
Dim myConn As ADODB.Connection
Dim myRecord As ADODB.Recordset

Private Sub Form_Load()
Form1.Visible = True
DoEvents
Set myConn = New ADODB.Connection
myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d: st.mdb;Persist Security Info=False"
myConn.Open
Set myRecord = New ADODB.Recordset
myRecord.Open "select * from Table1", myConn, adOpenDynamic, adLockOptimistic
Do Until myRecord.EOF
Debug.Print "Deleteing"
myRecord.Delete
myRecord.MoveNext
Loop
myRecord.Close
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set myRecord = Nothing
Set myConn = Nothing
End Sub

Comments

  • GideonOmegaGideonOmega Posts: 617Member
    : First,Create tst.mdb on drive D,then create a table named Table1,insert some data。Why it ONLY deletes 2 record? not all of them? Thanks a lot!
    :
    : Option Explicit
    : Dim myConn As ADODB.Connection
    : Dim myRecord As ADODB.Recordset
    :
    : Private Sub Form_Load()
    : Form1.Visible = True
    : DoEvents
    : Set myConn = New ADODB.Connection
    : myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d: st.mdb;Persist Security Info=False"
    : myConn.Open
    : Set myRecord = New ADODB.Recordset
    : myRecord.Open "select * from Table1", myConn, adOpenDynamic, adLockOptimistic
    : Do Until myRecord.EOF
    : Debug.Print "Deleteing"
    : myRecord.Delete
    : myRecord.MoveNext
    : Loop
    : myRecord.Close
    : End Sub
    :
    : Private Sub Form_Unload(Cancel As Integer)
    : Set myRecord = Nothing
    : Set myConn = Nothing
    : End Sub
    :
    :


    Try adding MyRecord.MoveFirst before your loop that way you are at the begining of your recordset - otherwise you will just delete everything from the point you are at.
    [blue]
    C:Dos
    C:Dos Run
    Run Dos Run
    [/blue]

  • tony0tony0 Posts: 7Member
    : : First,Create tst.mdb on drive D,then create a table named Table1,insert some data。Why it ONLY deletes 2 record? not all of them? Thanks a lot!
    : :
    : : Option Explicit
    : : Dim myConn As ADODB.Connection
    : : Dim myRecord As ADODB.Recordset
    : :
    : : Private Sub Form_Load()
    : : Form1.Visible = True
    : : DoEvents
    : : Set myConn = New ADODB.Connection
    : : myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d: st.mdb;Persist Security Info=False"
    : : myConn.Open
    : : Set myRecord = New ADODB.Recordset
    : : myRecord.Open "select * from Table1", myConn, adOpenDynamic, adLockOptimistic
    : : Do Until myRecord.EOF
    : : Debug.Print "Deleteing"
    : : myRecord.Delete
    : : myRecord.MoveNext
    : : Loop
    : : myRecord.Close
    : : End Sub
    : :
    : : Private Sub Form_Unload(Cancel As Integer)
    : : Set myRecord = Nothing
    : : Set myConn = Nothing
    : : End Sub
    : :
    : :
    :
    :
    : Try adding MyRecord.MoveFirst before your loop that way you are at the begining of your recordset - otherwise you will just delete everything from the point you are at.
    : [blue]
    : C:Dos
    : C:Dos Run
    : Run Dos Run
    : [/blue]
    :
    :

    I know the problem now, add "myConn.CursorLocation = adUseClient" and "myRecord.CursorLocation = adUseClient", i'll work ok.

    thanks for you help.
  • Termc1224Termc1224 Posts: 84Member
    : : : First,Create tst.mdb on drive D,then create a table named Table1,insert some data。Why it ONLY deletes 2 record? not all of them? Thanks a lot!
    : : :
    : : : Option Explicit
    : : : Dim myConn As ADODB.Connection
    : : : Dim myRecord As ADODB.Recordset
    : : :
    : : : Private Sub Form_Load()
    : : : Form1.Visible = True
    : : : DoEvents
    : : : Set myConn = New ADODB.Connection
    : : : myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d: st.mdb;Persist Security Info=False"
    : : : myConn.Open
    : : : Set myRecord = New ADODB.Recordset
    : : : myRecord.Open "select * from Table1", myConn, adOpenDynamic, adLockOptimistic
    : : : Do Until myRecord.EOF
    : : : Debug.Print "Deleteing"
    : : : myRecord.Delete
    : : : myRecord.MoveNext
    : : : Loop
    : : : myRecord.Close
    : : : End Sub
    : : :
    : : : Private Sub Form_Unload(Cancel As Integer)
    : : : Set myRecord = Nothing
    : : : Set myConn = Nothing
    : : : End Sub
    : : :
    : : :
    : :
    : :
    : : Try adding MyRecord.MoveFirst before your loop that way you are at the begining of your recordset - otherwise you will just delete everything from the point you are at.
    : : [blue]
    : : C:Dos
    : : C:Dos Run
    : : Run Dos Run
    : : [/blue]
    : :
    : :
    :
    : I know the problem now, add "myConn.CursorLocation = adUseClient" and "myRecord.CursorLocation = adUseClient", i'll work ok.
    :
    : thanks for you help.
    :

    To delete all use this
    : : : myRecord.Open "delete * from Table1", myConn, adOpenDynamic, adLockOptimistic, aduseclient

Sign In or Register to comment.