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

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.