![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
It was originally done in access 2003 and works fine. now it does not work in access 2007 and after an update it will not work in access 2003 either. I am confused Private Sub TableDeleteRecords(strTableName As String) Dim rst As Recordset * Set rst = CurrentDb.OpenRecordset(strTableName) * If rst.RecordCount = 0 Then Exit Sub * rst.MoveFirst * Do While Not (rst.EOF) * * rst.Delete * * rst.MoveNext * Loop * rst.Close End Sub when you pass any file to this rst.recordcount is always equal to 153. I even passed it a table with nothing in it and it still says 153. |
#3
| |||
| |||
|
|
On Aug 19, 9:52 am, sparks <spa... (AT) home (DOT) com> wrote: It was originally done in access 2003 and works fine. now it does not work in access 2007 and after an update it will not work in access 2003 either. I am confused Private Sub TableDeleteRecords(strTableName As String) Dim rst As Recordset Set rst = CurrentDb.OpenRecordset(strTableName) If rst.RecordCount = 0 Then Exit Sub rst.MoveFirst Do While Not (rst.EOF) rst.Delete rst.MoveNext Loop rst.Close End Sub when you pass any file to this rst.recordcount is always equal to 153. I even passed it a table with nothing in it and it still says 153. I thought one always needed to rst.movelast rst.movefirst first to get the correct recordcount.. |
#4
| |||
| |||
|
|
On Aug 19, 9:52 am, sparks <spa... (AT) home (DOT) com> wrote: It was originally done in access 2003 and works fine. now it does not work in access 2007 and after an update it will not work in access 2003 either. I am confused Private Sub TableDeleteRecords(strTableName As String) Dim rst As Recordset Set rst = CurrentDb.OpenRecordset(strTableName) If rst.RecordCount = 0 Then Exit Sub rst.MoveFirst Do While Not (rst.EOF) rst.Delete rst.MoveNext Loop rst.Close End Sub when you pass any file to this rst.recordcount is always equal to 153. I even passed it a table with nothing in it and it still says 153. I thought one always needed to rst.movelast rst.movefirst first to get the correct recordcount.. Microsoft help recommends you NOT use rst.movelast unless you need to know |
#5
| |||
| |||
|
|
It was originally done in access 2003 and works fine. now it does not work in access 2007 and after an update it will not work in access 2003 either. I am confused Private Sub TableDeleteRecords(strTableName As String) Dim rst As Recordset * Set rst = CurrentDb.OpenRecordset(strTableName) * If rst.RecordCount = 0 Then Exit Sub * rst.MoveFirst * Do While Not (rst.EOF) * * rst.Delete * * rst.MoveNext * Loop * rst.Close End Sub when you pass any file to this rst.recordcount is always equal to 153. I even passed it a table with nothing in it and it still says 153. |
#6
| |||
| |||
|
|
It was originally done in access 2003 and works fine. now it does not work in access 2007 and after an update it will not work in access 2003 either. I am confused Private Sub TableDeleteRecords(strTableName As String) Dim rst As Recordset Set rst = CurrentDb.OpenRecordset(strTableName) If rst.RecordCount = 0 Then Exit Sub rst.MoveFirst Do While Not (rst.EOF) rst.Delete rst.MoveNext Loop rst.Close End Sub when you pass any file to this rst.recordcount is always equal to 153. I even passed it a table with nothing in it and it still says 153. |
#7
| |||
| |||
|
|
I thought one always needed to rst.movelast rst.movefirst first to get the correct recordcount.. |
#8
| ||||
| ||||
|
|
Only if using a dynamic or keyset cursor. If using a static cursor, then the number of records is known when the recordset is populated. The thing is, when using a non-static cursor, RecordCount should contain -1, |
|
since the total number of records is not known until the last record is navigated to. |
|
So I'm very puzzled that it is always containing 153. |
|
To the OP: have you verified that strTableName contains what you think it contains? Add a Debug.Print strTableName line to verify it. Or add a breakpoint to step through the sub and inspect the variable's value. That said, I am really puzzled why a recordset is being used here to do the job of a DELETE query. The sub should be rewritten to this: Private Sub TableDeleteRecords(strTableName As String) Dim sql as String sql = "DELETE * FROM " & strTableName debug.print sql 'can be commented out when not debugging currentdb.execute sql, dbFailOnError End Sub |
#9
| |||
| |||
|
|
"Bob Barrows" <reb01501 (AT) NOSPAMyahoo (DOT) com> wrote in news:j2m372$u3f$1 (AT) dont-email (DOT) me: Only if using a dynamic or keyset cursor. If using a static cursor, then the number of records is known when the recordset is populated. The thing is, when using a non-static cursor, RecordCount should contain -1, Not in DAO -- that's ADO. |
|
One should never use dbFailOnError without an error handler. |
#10
| |||
| |||
|
|
It appears that you're missing an "End If" statement.... Fred If rst.RecordCount = 0 Then Exit Sub |
|
On Aug 19, 7:52*am, sparks <spa... (AT) home (DOT) com> wrote: It was originally done in access 2003 and works fine. now it does not work in access 2007 and after an update it will not work in access 2003 either. I am confused Private Sub TableDeleteRecords(strTableName As String) Dim rst As Recordset * Set rst = CurrentDb.OpenRecordset(strTableName) * If rst.RecordCount = 0 Then Exit Sub * rst.MoveFirst * Do While Not (rst.EOF) * * rst.Delete * * rst.MoveNext * Loop * rst.Close End Sub when you pass any file to this rst.recordcount is always equal to 153. I even passed it a table with nothing in it and it still says 153. |
![]() |
| Thread Tools | |
| Display Modes | |
| |