
loop not completing correctly
Here is a rewrite.
You didn't dim rs1 as a DAO.Recordset.
You aren't incrementing nextAvailableCounter
Public Function UpdateCheques()
On Error GoTo UpdateCheques_Err
Dim db As database
Dim rs1 as DAO.Recordset '<<------------
Dim rs2 As DAO.Recordset
Dim NextAvailableCounter As Long
Set db = CurrentDb
Set rs1 = db.OpenRecordset("Temp Cheque List")
Set rs2 = db.OpenRecordset("CounterTable")
'Get the next counter.
NextAvailableCounter = rs2!NextAvailableCounter
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Open the table and get the current value of
'NextAvailableNumber,
'increment the value by 1, and save the value back into
'the table
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Do Until rs1.EOF
rs1.Edit
rs1!ChequeNo = rs2!NextAvailableCounter
rs1.Update
rs2.Edit
NextAvailableCounter = NextAvailableCounter + 1 '<<-------
rs2!NextAvailableCounter = NextAvailableCounter '<<-------
rs2.Update
rs1.MoveNext
Loop
UpdateCheques_Exit:
rs1.Close
rs2.Close
db.Close
Exit Function
'This is only a temporary error routine cos it was going
'a perpetual loop and I haven't figured out how to write
one ...yet
UpdateCheques_Err:
MsgBox "Error " & Err & ": " & Error$
Resume UpDateCheques_Exit
End Function
Quote:
> I have written the following module (first attempt at one
> of these) - based around a lot of assistance gained from
> previous replies to this newsgroup. But I am encountering
> a problem on the loop section, the temporary table I am
> practising with has 4 records it updates the first and
> second correctly, but then repeats the number it enters
> into the second one on the third and fourth records. I am
> obviously missing something - can anyone possibly help.
> Oh I know the error bit is wrong - thats the next thing I
> have to work on.
> Thanks in advance.
> Joyce
> Public Function UpdateCheques()
> On Error GoTo UpdateCheques_Err
> Dim db As database
> Dim rs1, rs2 As DAO.Recordset
> Dim NextAvailableCounter As Long
> Set db = CurrentDb
> Set rs1 = db.OpenRecordset("Temp Cheque List")
> Set rs2 = db.OpenRecordset("CounterTable")
> 'Get the next counter.
> NextAvailableCounter = rs2!NextAvailableCounter
> '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> ''''''''
> 'Open the table and get the current value of
> NextAvailableNumber,
> 'increment the value by 1, and save the value back into
> the table
> '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> ''''''''
> Do Until rs1.EOF
> rs1.Edit
> rs2.Edit
> rs1!ChequeNo = rs2!NextAvailableCounter
> rs1.Update
> rs2!NextAvailableCounter = NextAvailableCounter + 1
> rs2.Update
> rs1.MoveNext
> Loop
> rs1.Close
> rs2.Close
> db.Close
> 'This is only a temporary error routine cos it was going
> into,
> 'a perpetual loop and I haven't figured out how to write
> one ...yet
> UpdateCheques_Err:
> MsgBox "Error " & Err & ": " & Error$
> End
> End Function