Form - Do Loop will not execte -

R

ridlt

Hi - My first post - What a great website

I'm having problems with the Do loop below - I can't get it to execute
I need the loop to re-calc balances. What is it that i'm doing wrong.

Thanks for any help - Tom
------------------------------------------------------------------------------
----------

Private Sub cmdCalc_Click()
'Recalc Balances
Dim douBegBal As Double
Dim douEndBal As Double

Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("tblContingency")


rst.MoveFirst
douEndBal = BegBalance

Do Until rst.EOF
BegBalance = douEndBal
EndBalance = BegBalance + Additions + Reductions
douEndBal = EndBalance
'rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing

End Sub
 
R

Rick Brandt

Hi - My first post - What a great website

I'm having problems with the Do loop below - I can't get it to execute I
need the loop to re-calc balances. What is it that i'm doing wrong.

Thanks for any help - Tom
------------------------------------------------------------------------------
----------

Private Sub cmdCalc_Click()
'Recalc Balances
Dim douBegBal As Double
Dim douEndBal As Double

Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("tblContingency")


rst.MoveFirst
douEndBal = BegBalance

Do Until rst.EOF
BegBalance = douEndBal
EndBalance = BegBalance + Additions + Reductions douEndBal =
EndBalance
'rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing

End Sub

You have commented out the MoveNext which means your loop is running. It
just will never finish.
 
R

ridlt

Thanks Rick for your response-

I did remove that comment line and the Do Loop still didn't execute.

Rick said:
Hi - My first post - What a great website

I'm having problems with the Do loop below - I can't get it to execute I
need the loop to re-calc balances. What is it that i'm doing wrong.

Thanks for any help - Tom
[quoted text clipped - 23 lines]

You have commented out the MoveNext which means your loop is running. It
just will never finish.
 
R

Rick Brandt

Thanks Rick for your response-

I did remove that comment line and the Do Loop still didn't execute.

Rick said:
Hi - My first post - What a great website

I'm having problems with the Do loop below - I can't get it to execute
I need the loop to re-calc balances. What is it that i'm doing wrong.

Thanks for any help - Tom
[quoted text clipped - 23 lines]

You have commented out the MoveNext which means your loop is running.
It just will never finish.

Well then, the next logical conclusion is that your recordset returns
zero rows and therefore "Do Until rst.EOF" is satisfied before the first
loop is executed.

Put in a break-point and see what is actually happening.
 
C

Chegu Tom

What are you doing in that loop? Are EndBalance, BegBalance, additions,
reductions fields in your recordset rst?

Try referencing them as rst!BegBalance. rst!Additions etc

Are you writing a new value for EndBalance in each record?
You need rst.edit and rst.update

Check the help under DAO Edit Method

Maybe something like this

rst.MoveFirst
douEndBal = rst!BegBalance

Do Until rst.EOF
rst.edit
rst!BegBalance = douEndBal
rst!EndBalance = rst!BegBalance + rst!Additions + rst!Reductions
douEndBal = rst!EndBalance
rst.update
rst.MoveNext
Loop
 
R

ridlt via AccessMonster.com

Chegu Tom -

Your code worked!
Thanks so much for your help - It's very much appreciated - I'm new to VBA
and with your assistance I'm starting to turn some corners.

Chegu said:
What are you doing in that loop? Are EndBalance, BegBalance, additions,
reductions fields in your recordset rst?

Try referencing them as rst!BegBalance. rst!Additions etc

Are you writing a new value for EndBalance in each record?
You need rst.edit and rst.update

Check the help under DAO Edit Method

Maybe something like this

rst.MoveFirst
douEndBal = rst!BegBalance

Do Until rst.EOF
rst.edit
rst!BegBalance = douEndBal
rst!EndBalance = rst!BegBalance + rst!Additions + rst!Reductions
douEndBal = rst!EndBalance
rst.update
rst.MoveNext
Loop
[quoted text clipped - 33 lines]
You have commented out the MoveNext which means your loop is running. It
just will never finish.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top