atadbitslow
Programmer
I get a "run-time Error 3021 No current record" when the code below is run......which just means it is at the end of the file---how do i get it to not error out? thanks-
Function PS()
Set db = CurrentDb
Set rs1 = db.OpenRecordset("SELECT [collections thank you batch].ID, [collections thank you batch].Expr2, [collections thank you batch].NAME_LAST, [collections thank you batch].NAME_FIRST, [collections thank you batch].expr1, [all].tempstring, [all].num_mergerecords FROM [all] INNER JOIN [collections thank you batch] ON [all].ID = [collections thank you batch].ID" _
& " ORDER BY [collections thank you batch].ID, [collections thank you batch].Expr2;"
rs1.MoveFirst
Do While Not rs1.EOF
' get data from first record
mmid = rs1.ID
mcat = StrConv(rs1.Expr2, vbProperCase) 'category
mtitle = rs1.Expr1 'TITLE
mcontb = StrConv((rs1.Expr2) & "(s)", vbProperCase) + Chr(13) + Chr(9) + Chr(9) + rs1.Expr1
rs1.MoveNext ' move to second record
Do While rs1.ID = mmid
Do While mcat = rs1.Expr2 And rs1.ID = mmid
mcontb = mcontb + Chr(13) + Chr(9) + Chr(9) + rs1.Expr1
rs1.MoveNext
If rs1.EOF Then Exit Do
Loop
rs1.MovePrevious
rs1.Edit
rs1.tempstring = mcontb
rs1.Update
rs1.MoveNext
If rs1.EOF Then Exit Do
mmid = rs1.ID
mcat = StrConv(rs1.Expr2, vbProperCase)
mtitle = rs1.Expr1
mcontb = Nz(rs1.tempstring) + Chr(13) + Chr(9) + StrConv((rs1.Expr2) & "(s)", vbProperCase)
Loop
rs1.MovePrevious
rs1.Edit
rs1.tempstring = mcontb
rs1.Update
rs1.MoveNext 'back to where we were
Loop
' handle the very last id sequence
On Error Resume Next
endjob:
rs1.MovePrevious
rs1.Edit
rs1.tempstring = mcontb
rs1.Update
On Error Resume Next
End Function
Function PS()
Set db = CurrentDb
Set rs1 = db.OpenRecordset("SELECT [collections thank you batch].ID, [collections thank you batch].Expr2, [collections thank you batch].NAME_LAST, [collections thank you batch].NAME_FIRST, [collections thank you batch].expr1, [all].tempstring, [all].num_mergerecords FROM [all] INNER JOIN [collections thank you batch] ON [all].ID = [collections thank you batch].ID" _
& " ORDER BY [collections thank you batch].ID, [collections thank you batch].Expr2;"
rs1.MoveFirst
Do While Not rs1.EOF
' get data from first record
mmid = rs1.ID
mcat = StrConv(rs1.Expr2, vbProperCase) 'category
mtitle = rs1.Expr1 'TITLE
mcontb = StrConv((rs1.Expr2) & "(s)", vbProperCase) + Chr(13) + Chr(9) + Chr(9) + rs1.Expr1
rs1.MoveNext ' move to second record
Do While rs1.ID = mmid
Do While mcat = rs1.Expr2 And rs1.ID = mmid
mcontb = mcontb + Chr(13) + Chr(9) + Chr(9) + rs1.Expr1
rs1.MoveNext
If rs1.EOF Then Exit Do
Loop
rs1.MovePrevious
rs1.Edit
rs1.tempstring = mcontb
rs1.Update
rs1.MoveNext
If rs1.EOF Then Exit Do
mmid = rs1.ID
mcat = StrConv(rs1.Expr2, vbProperCase)
mtitle = rs1.Expr1
mcontb = Nz(rs1.tempstring) + Chr(13) + Chr(9) + StrConv((rs1.Expr2) & "(s)", vbProperCase)
Loop
rs1.MovePrevious
rs1.Edit
rs1.tempstring = mcontb
rs1.Update
rs1.MoveNext 'back to where we were
Loop
' handle the very last id sequence
On Error Resume Next
endjob:
rs1.MovePrevious
rs1.Edit
rs1.tempstring = mcontb
rs1.Update
On Error Resume Next
End Function