By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

No Current Record error

P: 14
using ACCESS 2003
This code should do what I want, and it seems to, but every time i run it it says:
No Current Record

when i ctrl+break it the debug get hung up on the end sub.

heres the code, any ideas? :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command16_Click()
  2. On Error GoTo Err_Command16_Click
  3. Dim i As Integer, cnt As Integer, varBk As String
  4. Dim intCriteriaCount As Integer, MyDB As Database, MyRS As Recordset
  5. Dim intCounter As Integer
  6.  
  7. varBk = Me.Bookmark
  8. cnt = Me!Combo17
  9.  
  10. For i = 0 To cnt - 1
  11. DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  12. DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
  13. DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
  14.  
  15. Me!Text22 = Me!Text22 + 1
  16.  
  17. Next
  18.  
  19. intCriteriaCount = DCount("*", "FindDuplicatesWeeklyPoints")
  20. intCriteriaCount = intCriteriaCount / 2 + 1
  21.  
  22. 'Are there Records meeting the Criteria?
  23. If intCriteriaCount > 0 Then
  24.   Set MyDB = CurrentDb()
  25.   'Order by your Primary Key Ascending
  26.   Set MyRS = MyDB.OpenRecordset("SELECT * FROM  FindDuplicatesWeeklyPoints ORDER BY [Weekly Index]")
  27.   MyRS.MoveLast: MyRS.MoveFirst
  28.     For intCounter = 1 To intCriteriaCount - 1      'All but the Last Record
  29.       MyRS.Delete
  30.       MyRS.MoveNext
  31.     Next
  32. Exit_Command16_Click:
  33. Me.Bookmark = varBk
  34.  
  35.  
  36. Else
  37.   Exit Sub
  38. End If
  39.  
  40. MyRS.Close
  41. Exit Sub
  42.  
  43. Err_Command16_Click:
  44. MsgBox Err.Description
  45.  
  46. End Sub
  47.  
Mar 18 '07 #1
Share this Question
Share on Google+
2 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
OK I've tidied up the code a bit. See if this works. If not let me know.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command16_Click()
  2. On Error GoTo Err_Command16_Click
  3. Dim i As Integer, cnt As Integer
  4. Dim varBk As String
  5. Dim intCriteriaCount As Integer
  6. Dim MyDB As Database
  7. Dim MyRS As Recordset
  8. Dim intCounter As Integer
  9.  
  10.    varBk = Me.Bookmark
  11.    cnt = Me!Combo17
  12.  
  13.    For i = 0 To cnt - 1
  14.       DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  15.       DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
  16.       DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70
  17.       'Paste Append
  18.       Me!Text22 = Me!Text22 + 1
  19.    Next
  20.  
  21.    intCriteriaCount = DCount("*", "FindDuplicatesWeeklyPoints")
  22.    intCriteriaCount = intCriteriaCount / 2 + 1
  23.  
  24.    'Are there Records meeting the Criteria?
  25.    If intCriteriaCount > 0 Then
  26.       Set MyDB = CurrentDb()
  27.       'Order by your Primary Key Ascending
  28.       Set MyRS = MyDB.OpenRecordset("SELECT * FROM FindDuplicatesWeeklyPoints ORDER BY [Weekly Index]")
  29.       MyRS.MoveLast: MyRS.MoveFirst
  30.       For intCounter = 1 To intCriteriaCount - 1      'All but the Last Record
  31.          MyRS.Delete
  32.          MyRS.MoveNext
  33.       Next
  34.    End If
  35. Exit_Command16_Click:
  36.    Me.Bookmark = varBk
  37.    MyRS.Close
  38.    Exit Sub
  39.  
  40. Err_Command16_Click:
  41.    MsgBox Err.Description
  42.     Resume Exit_Command16_Click
  43.  
  44. End Sub
  45.  
Mar 18 '07 #2

P: 14
sorry i haven't tried it, i actually managed to get it to work by changing:
Expand|Select|Wrap|Line Numbers
  1. If intCriteriaCount > 0 Then
to

Expand|Select|Wrap|Line Numbers
  1. If intCriteriaCount > 1 Then
what was changed in your code?


thanks for the help anyway
Mar 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.