stuckagain1
Technical User
Can anyone explain why the code below bombs out at the ** (** is not in the code). the error message is run-time 3021, no current record. there are two records in the table with different ids...thanks--
Function Petlib()
Set db = CurrentDb
Set rs1 = db.OpenRecordset("SELECT [collections thank you batch PET lib].donor_id, [collections thank you batch pet lib].NAME_LAST, [collections thank you batch pet lib].NAME_FIRST,[collections thank you batch pet lib].Expr2, [collections thank you batch pet lib].expr1,[all].[num_mergerecords],[all].tempstring" _
& " FROM [all] INNER JOIN [collections thank you batch pet lib] ON [all].ID = [collections thank you batch pet lib].donor_ID ORDER BY [collections thank you batch pet lib].donor_ID, [collections thank you batch pet lib].Expr2;")
rs1.MoveFirst
Do While Not rs1.EOF
' get data from first record
mmid = rs1.DONOR_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
**error! Do While rs1.DONOR_ID = mmid
Do While mcat = rs1.Expr2 And rs1.DONOR_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.DONOR_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 Petlib()
Set db = CurrentDb
Set rs1 = db.OpenRecordset("SELECT [collections thank you batch PET lib].donor_id, [collections thank you batch pet lib].NAME_LAST, [collections thank you batch pet lib].NAME_FIRST,[collections thank you batch pet lib].Expr2, [collections thank you batch pet lib].expr1,[all].[num_mergerecords],[all].tempstring" _
& " FROM [all] INNER JOIN [collections thank you batch pet lib] ON [all].ID = [collections thank you batch pet lib].donor_ID ORDER BY [collections thank you batch pet lib].donor_ID, [collections thank you batch pet lib].Expr2;")
rs1.MoveFirst
Do While Not rs1.EOF
' get data from first record
mmid = rs1.DONOR_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
**error! Do While rs1.DONOR_ID = mmid
Do While mcat = rs1.Expr2 And rs1.DONOR_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.DONOR_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