473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

A trap to avoid

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
12 4395
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Mike D | last post by:
I have a table in SQL 2000 with a composite Primary Key on coulumns Instrument_ID (int) and WeekOf (smalldatetime.) I am running asp on win 2003. I insert values using a stored procedure from...
2
by: aj | last post by:
DB2 WSE LUW 8.1 Fixpak 5 Red Hat AS 2.1 Has anyone ever seen a db2diag.log indicate that a trap file was written, but it is *not* written? For the 3rd time in 18 months, I had a production...
18
by: Mantorok Redgormor | last post by:
What does a trap representation mean in the standard? And how can ~0 cause a trap representation? Could someone point out the relevant sections in the standard?
0
by: OC | last post by:
Because of the requirements on a high-speed data entry form, I need to reliably trap certain keys (specifically the "/", "*", "-", and "+") keys on the 10-key pad and treat them as "Function keys"....
10
by: pemo | last post by:
As far as I understand it, a trap representation means something like - an uninitialised automatic variable might /implicitly/ hold a bit-pattern that, if read, *might* cause a 'trap' (I'm not...
6
by: temper3243 | last post by:
Hi Can someone explain me what is happening below ? Why is it printing 401380 $ cat scanf.c #include<stdio.h> int main() { int i; scanf(" %d",&i);
1
by: p.lavarre | last post by:
Is this interesting Python output? $ gc-object-already-tracked.py ********************************************************************** File...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.