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

A trap to avoid

P: n/a
Since reading values from calculated controls in Access 2000 and 2002 from
code has proven unrliable at best, and since I like to avoid running
separate queries to calculate sums of subform records since they can give
inconsistent results if there's more than on interface or user with access
to the table, I wrote code to loop through a subform's RecordsetClone to
calculate aggregate values.

This approach worked fine until I moved to a master record with no related
records in the subform. After moving to that record, the subform returned
an empty recordset clone from then on even after I moved back to a parent
row with related records, and they appeared in the subform.

The work-around I came up with was to write a function that takes a form as
a parameter and returns the form's RecordsetClone if the form has a record
count > 1 not counting the new record if the current record is new. If the
form's record count is zero, the function returns Nothing, and does not
attempt to access the form's RecordsetClone. This solved the problem.

Just thought y'all might want to know.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.
Nov 12 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Steve, thanks for posting your tips appreciated.

The bit that still worries me about this is if the subform is filtered.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:4a********************************@4ax.com...
Since reading values from calculated controls in Access 2000 and 2002 from
code has proven unrliable at best, and since I like to avoid running
separate queries to calculate sums of subform records since they can give
inconsistent results if there's more than on interface or user with access
to the table, I wrote code to loop through a subform's RecordsetClone to
calculate aggregate values.

This approach worked fine until I moved to a master record with no related
records in the subform. After moving to that record, the subform returned
an empty recordset clone from then on even after I moved back to a parent
row with related records, and they appeared in the subform.

The work-around I came up with was to write a function that takes a form as a parameter and returns the form's RecordsetClone if the form has a record
count > 1 not counting the new record if the current record is new. If the form's record count is zero, the function returns Nothing, and does not
attempt to access the form's RecordsetClone. This solved the problem.

Just thought y'all might want to know.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.

Nov 12 '05 #2

P: n/a
On Sep 05 2003, 09:17 pm, Steve Jorgensen <no****@nospam.nospam> wrote
in news:4a********************************@4ax.com:
Since reading values from calculated controls in Access 2000 and 2002
from code has proven unrliable at best


Steve,

Maybe this has been covered recently and I just missed it, but can you
elaborate a bit? Is there a difference from the way it works in Access 97?

--
(remove a 9 to reply by email)
Nov 12 '05 #3

P: n/a
Steve Jorgensen wrote:
Since reading values from calculated controls in Access 2000 and 2002
from code has proven unrliable at best, and since I like to avoid
running separate queries to calculate sums of subform records since
they can give inconsistent results if there's more than on interface
or user with access to the table, I wrote code to loop through a
subform's RecordsetClone to calculate aggregate values.

This approach worked fine until I moved to a master record with no
related records in the subform. After moving to that record, the
subform returned an empty recordset clone from then on even after I
moved back to a parent row with related records, and they appeared in
the subform.

The work-around I came up with was to write a function that takes a
form as a parameter and returns the form's RecordsetClone if the form
has a record count > 1 not counting the new record if the current
record is new. If the form's record count is zero, the function
returns Nothing, and does not attempt to access the form's
RecordsetClone. This solved the problem.

Just thought y'all might want to know.
Yeah, nice one Steve, or should I say 'arrrghh' - another way my app might
break because i have similar code running somewhere...


- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.


Nov 12 '05 #4

P: n/a
On 6 Sep 2003 02:25:05 GMT, Dimitri Furman <df*****@cloud99.net> wrote:
On Sep 05 2003, 09:17 pm, Steve Jorgensen <no****@nospam.nospam> wrote
in news:4a********************************@4ax.com:
Since reading values from calculated controls in Access 2000 and 2002
from code has proven unrliable at best


Steve,

Maybe this has been covered recently and I just missed it, but can you
elaborate a bit? Is there a difference from the way it works in Access 97?


I don't know if it's been covered here, but I've exprienced it, and other
developers I've talked to have as well. Basically, it seems as if, in
Access 97 (the good ol' days for things like this), if you try to read the
value of a calculated control, that forces everything to wait while the
calculation gets all its dependencies in order and produces a result.
Also, in Access 97, if one calculation happens to be temporarily broken,
all unrelated calculations continue to work.
In Access 2000 and 2002, on the other hand, if you try to read the value of
a calculation from code, if Access hasn't gotten around to completing the
calculation, it can give you a Null instead. There don't seem to be any
reiable work-arounds, and I and others have treid really hard to come up
with them.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.
Nov 12 '05 #5

P: n/a
An update on this problem. I was checking for an empty recordset using
rst.EOF and rst.BOF. I do this because I know that .RecordCount is
unreliable until the last record has been navigated to. In my code, once
the RecordSetClone has been empty. EOF and BOF continue to be true whether
it is still empty or not. but .RecordCount is >0 if there are records. All
I had to do was check the .RecordCount as well as .EOF and .BOF, and
everything's fine.

On Sat, 06 Sep 2003 01:17:20 GMT, Steve Jorgensen <no****@nospam.nospam>
wrote:
Since reading values from calculated controls in Access 2000 and 2002 from
code has proven unrliable at best, and since I like to avoid running
separate queries to calculate sums of subform records since they can give
inconsistent results if there's more than on interface or user with access
to the table, I wrote code to loop through a subform's RecordsetClone to
calculate aggregate values.

This approach worked fine until I moved to a master record with no related
records in the subform. After moving to that record, the subform returned
an empty recordset clone from then on even after I moved back to a parent
row with related records, and they appeared in the subform.

The work-around I came up with was to write a function that takes a form as
a parameter and returns the form's RecordsetClone if the form has a record
count > 1 not counting the new record if the current record is new. If the
form's record count is zero, the function returns Nothing, and does not
attempt to access the form's RecordsetClone. This solved the problem.

Just thought y'all might want to know.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.
Nov 12 '05 #6

P: n/a
Steve Jorgensen <no****@nospam.nospam> wrote:
The work-around I came up with was to write a function that takes a form as
a parameter and returns the form's RecordsetClone if the form has a record
count > 1 not counting the new record if the current record is new. If the
form's record count is zero, the function returns Nothing, and does not
attempt to access the form's RecordsetClone. This solved the problem.


Very nice. I've had a similar problem a few years ago in which I was having some
similar wierd problems.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 12 '05 #7

P: n/a
On Sat, 06 Sep 2003 23:31:13 GMT, Chuck Grimsby
<c.*******@worldnet.att.net.invalid> wrote:

For what it's worth, I just check for .BOF when doing this, stepping
through backwards. I don't even bother with .EOF, since I'm stepping
through backwards, I know I'm never going to hit that!

Experience had taught me that .EOF isn't always accurate, but .BOF
always is.


In this case, I was checking EOF and BOF before doing any navigation since
getting a new reference from .RecordsetClone. It seems that changing to a
less restrictive filter was not clearing either .EOF or .BOF after they got
set, so I don't know what that means in terms of the accuracy of either
one. I guess one could say it's by design since the values were correct
after the previous navigation, and no further navigation was done, just a
change in filtering.

Regarding the use of .RecordCount here to check for non-empty, I think it's
safe. Although, the value may not always be accurate, I've never seen a
case where it was zero for a non-empty recordset. It seems to at least
read the first row and count that in all cases. In fact, given that,
there's probably no point in using .EOF or .BOF in the condition at all.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.
Nov 12 '05 #8

P: n/a
On Sun, 07 Sep 2003 10:34:59 GMT, Chuck Grimsby
<c.*******@worldnet.att.net.invalid> wrote:
....
Regarding the use of .RecordCount here to check for non-empty, I think it's
safe. Although, the value may not always be accurate, I've never seen a
case where it was zero for a non-empty recordset. It seems to at least
read the first row and count that in all cases. In fact, given that,
there's probably no point in using .EOF or .BOF in the condition at all.


True. I've done that as well. I can't say as .RecordCount has ever
failed me either. (Well, when I don't forget to do a .MoveLast first
however! <Grin>)


Of course, here, I need to make sure there is more than one record -before-
attempting to do a .MoveLast, or any other move unless I'm going to use On
Error Resume Next.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.
Nov 12 '05 #9

P: n/a
c.*******@worldnet.att.net.invalid (Chuck Grimsby) wrote in
<01********************************@4ax.com>:
On Sun, 07 Sep 2003 00:17:47 GMT, Steve Jorgensen
<no****@nospam.nospam> wrote:
Regarding the use of .RecordCount here to check for non-empty, I
think it's safe. Although, the value may not always be accurate,
I've never seen a case where it was zero for a non-empty
recordset. It seems to at least read the first row and count
that in all cases. In fact, given that, there's probably no
point in using .EOF or .BOF in the condition at all.


True. I've done that as well. I can't say as .RecordCount has
ever failed me either. (Well, when I don't forget to do a
.MoveLast first however! <Grin>)


You don't need to do a .MoveLast unless you want an accurate
non-zero recordcount. When .RecordCount returns 0, it is always
reliable -- you have an empty recordset. If it returns something
else, then you know you have a non-empty recordset, but you won't
know the exact count of records until you do your .MoveLast.

I think y'all are confusing two questions here, both of which can
be answered by .RecordCount:

1. how many records are in the recordset -- requires .MoveLast

2. whether the recordset is empty or not -- requires only a check
if the .RecordCount is 0 or not.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #10

P: n/a
On Sun, 07 Sep 2003 21:11:56 GMT, dX********@bway.net (David W. Fenton)
wrote:
c.*******@worldnet.att.net.invalid (Chuck Grimsby) wrote in
<01********************************@4ax.com>:
On Sun, 07 Sep 2003 00:17:47 GMT, Steve Jorgensen
<no****@nospam.nospam> wrote:
Regarding the use of .RecordCount here to check for non-empty, I
think it's safe. Although, the value may not always be accurate,
I've never seen a case where it was zero for a non-empty
recordset. It seems to at least read the first row and count
that in all cases. In fact, given that, there's probably no
point in using .EOF or .BOF in the condition at all.


True. I've done that as well. I can't say as .RecordCount has
ever failed me either. (Well, when I don't forget to do a
.MoveLast first however! <Grin>)


You don't need to do a .MoveLast unless you want an accurate
non-zero recordcount. When .RecordCount returns 0, it is always
reliable -- you have an empty recordset. If it returns something
else, then you know you have a non-empty recordset, but you won't
know the exact count of records until you do your .MoveLast.

I think y'all are confusing two questions here, both of which can
be answered by .RecordCount:

1. how many records are in the recordset -- requires .MoveLast

2. whether the recordset is empty or not -- requires only a check
if the .RecordCount is 0 or not.


Cool - that confirms how I'm using RecordCount in this case. I don't need
or try to get an accurate record count up-front because I'm about to loop
through the records, and EOF will tell me when I'm done.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.
Nov 12 '05 #11

P: n/a
On Sun, 07 Sep 2003 21:09:11 GMT, dX********@bway.net (David W. Fenton)
wrote:
no****@nospam.nospam (Steve Jorgensen) wrote in
<rk********************************@4ax.com>:
An update on this problem. I was checking for an empty recordset
using rst.EOF and rst.BOF. I do this because I know that
.RecordCount is unreliable until the last record has been
navigated to. . . .
Not true. The .RecordCount never returns anything but 0 if the
recordset is empty. It returns an unreliable number if it is *not*
empty, but since you don't care exactly how many records there are,
checking the .RecordCount is sufficient.


By unreliable, here, I just meant the actual count, not that I think it's
unreliable for determining empty/non-empty. It's nice to get confirmation
on this, though.
. . . In my code, once the RecordSetClone has been empty.
EOF and BOF continue to be true whether it is still empty or not.
but .RecordCount is >0 if there are records. All I had to do was
check the .RecordCount as well as .EOF and .BOF, and everything's
fine.


You shouldn't need to check .EOF and .BOF at all.


Right, that's what my code now assumes since .EOF and .BOF are obviously
not helpful in this case.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn't have the time.
Nov 12 '05 #12

P: n/a
Bri
Steve,

I have had the problem with calculated values in Access 97 as well. I tried all
sorts of things like DoEvents and Me.Refresh to try to get the calculated values
to finish calculating before a reference to them and was unable to do it. I
opted for the separate query method at the time as the records are in a temp
table on the workstation so the execution time was unnoticable. The
RecordsetClone method will be handy for the next time, particularly if the table
is in the backend of a slow network (is there any other kind?).

--
Bri

Steve Jorgensen wrote:

Since reading values from calculated controls in Access 2000 and 2002 from
code has proven unrliable at best, and since I like to avoid running
separate queries to calculate sums of subform records since they can give
inconsistent results if there's more than on interface or user with access
to the table, I wrote code to loop through a subform's RecordsetClone to
calculate aggregate values.

Nov 12 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.