Result set access in VBA

Paul Wagner

Registered User.
Local time
Today, 08:30
Joined
May 18, 2004
Messages
48
Why is this not a valid construct from within a form? Specifically, when I put in the msgbox the whole operation just simply fails (no msgbox, no breakpoint). It works fine when I take out the Msgbox

Dim db As Database
Dim QD As QueryDef
Dim RS As Recordset
Set db = CurrentDb
'
Set QD = db.QueryDefs("A")
Set RS = QD.OpenRecordset
Do While Not RS.EOF
MsgBox "test=" & RS![SumOfChargeNetOut]
Me!txtExample = RS![SumOfChargeNetOut]
Me![txtChargesInCurrMo] = RS![SumOfChargeNetIn]
RS.MoveNext
Loop
RS.Close
db.Close
Set db = Nothing
 
Paul Wagner said:
Why is this not a valid construct from within a form? Specifically, when I put in the msgbox the whole operation just simply fails (no msgbox, no breakpoint). It works fine when I take out the Msgbox

Dim db As Database
Dim QD As QueryDef
Dim RS As Recordset
Set db = CurrentDb
'
Set QD = db.QueryDefs("A")
Set RS = QD.OpenRecordset
Do While Not RS.EOF
MsgBox "test=" & RS![SumOfChargeNetOut]
Me!txtExample = RS![SumOfChargeNetOut]
Me![txtChargesInCurrMo] = RS![SumOfChargeNetIn]
RS.MoveNext
Loop
RS.Close
db.Close
Set db = Nothing

I think the problem is that you don't use a MoveFirst to go to the first record.
Try adding RS.MoveFirst (At least I think that's the DAO syntax) before the loop.

-Patrick.
 

Users who are viewing this thread

Back
Top Bottom