"MP" <no****@Thanks. comwrote in
news:1m******** **********@torn ado.rdc-kc.rr.com:
One more question about Expression Service
After some googling it appears that is not available when hitting
an mdb via ado or dao?
Well, I tried to investigate to figure out a proper answer on this,
but I am stumped now. There are references in Google and on MS's
website to the "Jet Expression Service" and then there are
references to the "Access Expression Service." It seems as though
they are the same thing, but it's not clear to me that they are.
Does anyone know the answer to that?
In any event, some things work and some don't. I'm pretty sure IIf()
will work via ODBC but Nz() won't, because Nz() is a VBA function
while IIf() is an internal Jet Expression Service function.
Maybe.
That's my understanding that it's something like that.
In any event, you shouldn't count on UDFs or any non-SQL functions
to work through any of the database interfaces, whether native Jet
(DAO) or not (ADO/ODBC).
"David W. Fenton" <XX*******@dfen ton.com.invalid wrote in message
news:Xn******** *************** **********@127. 0.0.1...
By passing the value, you're
>telling the Access Expression Service "Hey! The value returned
can change with each row, so you can't just check it once!"
so I assume I need to create my own iterating function and
determine through examining the field.values when to call it or
not call it...for each record in the recordset...
am i correct in this assumption?
Hmm. I thought you wanted it to be different on each row?
Let me outline what I understood:
1. you open a DISTINCT recordset to get the 5 unique groups.
2. you then run a SQL UPDATE on each group.
3. in each group, each row should increment.
Now, that's where I may have misunderstood. Is it that the first
group should be 1, the second 2 and so forth? If that's the case,
then you'd want to write you update SQL with a literal value, and
you could get that from the counter you use when walking through the
records of the DISTINCT query.
If, on the other hand, you need to increment within a group only
when certain values change, you'll want to make the parameter a
useful one, and evaluate it to see if you want to increment. If
you've got multiple arguments you may need to define multiple
parameters, or use a ParamArray(), though you'll have to be sure you
always pass the field values in the same order.
I tried the ReturnCounter function in my sql sent via
ado.connection. Execute(sSql)
and it appeared to work sometimes but not others...but I wasn't
positive which field value to send to it as the first argument..
I wouldn't expect it to work in ADO (I don't use ADO. Ever.), only
in DAO.
I had understood from your description that i would pass a field
object as first arg.
You pass the field:
SELECT ID, ReturnCounter([ID]) As Counter
etc.
the experession service would examine the value of that field and
compare it to a magically stored value from the previous time this
function was called (in the previous record),
No. Jet creates a query plan, deciding the order in which to do
operations in your SQL. If there's a join and WHERE clause, it will
decide which is the most efficient way to do it. Say, for instance,
you have a join between two tables of more-or-less the same number
of rows, but there's a criterion on one of the tables. The smart
thing to do is filter that table first, then do the join with the
other table, rather then joining all the records first and then
doing the select.
This is part of Jet's innards and is normal.
The last thing that happens is that anything that is *not* a SQL
command gets passed off to the Jet Expression Service. This is how
IIf() would get processed, and Left() and so forth. My understanding
(which could be completely wrong!) is that if it's not a Jet
function, it passes it off to the *Access* expression service, which
allows the query to use UDFs.
Now it could be that the Expression Service is one service that goes
by two names, but the point is that this happens last of all, after
the SQL has been optimized. And what happens is that the expression
service examines the SQL and sees if the function can be evaluated
just once (if you put Date() in there somewhere, it would be
evaluated once, since it has no dependency on data in each row) or
if it must be re-evaluated for each row.
What happens in each row with the function I wrote is that the
expression service evaluates it for each row, and the STATIC
variable stores the previous value.
and if this value differed from previous value the
expression was evaluated (the counter was incremented) but if this
value was the same as the previous value, the expression would not
be evaluated....
The expression service doesn't look at the return values. It only
looks at the *structure* of the function call. If a row value is
passed to the function, it evaluates it for each row, if not, it
evaluates it only once.
was this a correct understanding of how expressionservi ce would
work(if it were available...ie if i were using access...(which I'm
not))
Not entirely. I'd think you could still use this if you were using
DAO, but maybe I'm wrong. I never program in anything but Access.
from the google information saying Expression Service is not
available in a call from ado or dao to a jet database,
i assume I need to save my own "PreviousVa lue" and when
"thisValue" <"PreviousValue " then Increment Else DontIncrement
That's not possible in pure Jet SQL.
is that a correct assumption?
maybe something similar to:
Function IncrementUponCh ange (NewValue as variant, Optional Reset
as Boolean) as long
Static LastValue as variant
Static Counter as long
Const StartValue as Long = 1
If Reset Then
Counter = StartValue
Else
If NewValue <LastValue Then
Counter = Counter +1
LastValue = NewValue
End if
End if
IncrementUponCh ange = Counter
End Function
does that make any sense?
Not to me, as it won't get around the problem if DAO can't use the
expression service. It matters not what your function is -- either
DAO can evaluate it through the expression service or it can't. If
it can't, rewriting the function isn't going to change anything.
--
David W. Fenton
http://www.dfenton.com/
usenet at dfenton dot com
http://www.dfenton.com/DFA/