By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,124 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,124 IT Pros & Developers. It's quick & easy.

recordsets - problem

P: n/a
Consider this code please:

Private Sub Command17_Click()

Dim Db As DAO.Database
Dim Rec As DAO.Recordset
Dim TotMins As Integer

Set Db = CurrentDb()
Set Rec = Db.OpenRecordset("Tbl_PlayerMatch", dbOpenDynaset)

Do Until Rec.EOF
TotMins = TotMins + Rec!MinutesPlayed
Rec.MoveNext
Loop

Rec.Close

End Sub
Why is it that

1) <out of context> is displayed when I debug on Rec!MinutesPlayed.
2) Seems to read past EOF. Displays <out of context> for TotMins and
Rec!MinutesPlayed after last rec processed. Can't not get Totmins
displayed because of this

Many thanks
Geoff
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Geoff" <g.*****@ntlworld.com> wrote in message
news:eTO0c.2128$GQ.834@newsfe1-win...
Consider this code please:

Private Sub Command17_Click()

Dim Db As DAO.Database
Dim Rec As DAO.Recordset
Dim TotMins As Integer

Set Db = CurrentDb()
Set Rec = Db.OpenRecordset("Tbl_PlayerMatch", dbOpenDynaset)

Do Until Rec.EOF
TotMins = TotMins + Rec!MinutesPlayed
Rec.MoveNext
Loop

Rec.Close

End Sub
Why is it that

1) <out of context> is displayed when I debug on Rec!MinutesPlayed.
2) Seems to read past EOF. Displays <out of context> for TotMins and
Rec!MinutesPlayed after last rec processed. Can't not get Totmins
displayed because of this

Many thanks
Geoff


A few thoughts:
Any reason not to simply use a DSUM function?
Are you sure MinutesPlayed cannot contain a null value? Because, for
example, 25 + Null = Null, it is common practice to use the Nz function, if
this is the case.
For these sort of loops do you not include some generic error handling?
Common practice in this newsgroup is to set object variables to nothing as a
final step before exiting a sub.
Fletcher
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.