No Current Record error, can't work out why?

capdownlondon

Registered User.
Local time
Today, 20:26
Joined
Mar 18, 2007
Messages
52
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? :

Private Sub Command16_Click()
On Error GoTo Err_Command16_Click
Dim i As Integer, cnt As Integer, varBk As String
Dim intCriteriaCount As Integer, MyDB As Database, MyRS As Recordset
Dim intCounter As Integer

varBk = Me.Bookmark
cnt = Me!Combo17


For i = 0 To cnt - 1
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

Me!Text22 = Me!Text22 + 1



Next






intCriteriaCount = DCount("*", "FindDuplicatesWeeklyPoints")
intCriteriaCount = intCriteriaCount / 2 + 1

'Are there Records meeting the Criteria?
If intCriteriaCount > 0 Then
Set MyDB = CurrentDb()
'Order by your Primary Key Ascending
Set MyRS = MyDB.OpenRecordset("SELECT * FROM FindDuplicatesWeeklyPoints ORDER BY [Weekly Index]")
MyRS.MoveLast: MyRS.MoveFirst
For intCounter = 1 To intCriteriaCount - 1 'All but the Last Record
MyRS.Delete
MyRS.MoveNext
Next
Exit_Command16_Click:
Me.Bookmark = varBk


Else
Exit Sub
End If

MyRS.Close


Exit Sub

Err_Command16_Click:
MsgBox Err.Description



End Sub​
 
My guess is that it is this line tripping you up:

For intCounter = 1 To intCriteriaCount - 1

Do you have more than one record in the recordset at that time? If you have only one record then intCriteriaCount-1 would be zero and then you would be setting intCounter = 1 to 0.
 
My guess is that it is this line tripping you up:

For intCounter = 1 To intCriteriaCount - 1

Do you have more than one record in the recordset at that time? If you have only one record then intCriteriaCount-1 would be zero and then you would be setting intCounter = 1 to 0.

Thanks for that, but im not any wiser on what to do?
Im new to this, and i grabbed 2 bits of code and put them together, and fiddled around a little, kinda trial and error.

the problem is it does what i want, but it just comes up with the error if there are no duplicates already, but when there are any duplicates it works fine.

What would you suggest i do?
 
Try changing this:
Code:
If intCriteriaCount > 0 Then
to this:
Code:
If intCriteriaCount >[COLOR="Red"][B] 1[/B][/COLOR] Then
 

Users who are viewing this thread

Back
Top Bottom