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

  • : 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]

  • : : 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.
  • : : : 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.

Howdy, Stranger!

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

Categories