473,419 Members | 1,698 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,419 software developers and data experts.

How do I set an Aggregate SQL statement result to a control?

I would like to do something like this using VBA in MS Access 2000:

Me.num = "SELECT MAX(num) FROM mytable;"

How does one do that in MS Access correctly? Aggregates in SQL are
SUM, MAX, MIN which return only one value.*
* unless of course they are "grouped by" which I'm not doing...

Thanks for all your help in advance. It is much apprieciated!

Dec 13 '05 #1
8 1624

"Karen Hill" <ka**********@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I would like to do something like this using VBA in MS Access 2000:

Me.num = "SELECT MAX(num) FROM mytable;"

How does one do that in MS Access correctly? Aggregates in SQL are
SUM, MAX, MIN which return only one value.*
* unless of course they are "grouped by" which I'm not doing...

Thanks for all your help in advance. It is much apprieciated!


You should check out the Domain Aggregate Functions - DMax, DMin, DAvg, etc

--
Randy Harris
I'm pretty sure I know everything that I can remember.

Dec 13 '05 #2
DAO
me.num = DBEngine(0)(0).OpenRecordset("SELECT MAX(num) FROM
mytable").Collect(0)

ADO
me.num = CurrentProject.Connection.Execute("SELECT MAX(num) FROM
mytable").Collect(0)

Dec 13 '05 #3
Lyle Fairfield <ly***********@aim.com> wrote:
: me.num
: means
: I can't feel anything in my butt
: or
: I have a form with a control called num on it

: me.num = DBEngine(0)(0).OpenRecordset("SELECT MAX(num) FROM
: mytable").Collect(0)

Thanks: you've got most of the tangles. But is DBEngine(0)(0)
different from 'me' in this context?

--thelma

Dec 13 '05 #4
Thelma Lubkin wrote:
Lyle Fairfield <ly***********@aim.com> wrote:
: me.num
: means
: I can't feel anything in my butt
: or
: I have a form with a control called num on it

: me.num = DBEngine(0)(0).OpenRecordset("SELECT MAX(num) FROM
: mytable").Collect(0)

Thanks: you've got most of the tangles. But is DBEngine(0)(0)
different from 'me' in this context?

Very different:

DBEngine is the top level object of DAO. DBEngine(0) is the first
Workspace. DBEngine(0)(0) is the first Database of the first Workspace.
This should be your Database, the current Database, unless you have run
some very bad wizards which may make themselves DBEngine(0)(0). Many
developers use CurrentDB instead of DBEngine(0)(0) to avoid this
problem. Others, like me, never use wizards, at least not knowingly, or
without a struggle, or unless they are wizards we are convinced are good
wizards.

Me refers to the current class object (form or report), or class, that
is the object where the VBA code in which Me is written. In this case,
Num is a Control, Let Property or Modularly-Scoped Variable of the
current form or report, or Let Property or Modularly-Scoped Variable of
the currently running class.

What the code probably does is look up the maximum value of Num and show
it in a form control called Num.

Thelma I've seen a few posts from you. They were clever and
knowledgeable. One of these is true:

You already knew all this and much more and were just asking to see
where this might go, or for clarification;
Your learning has progressed much further in some areas than others;
I am mistaken about what I read.

In any case there will be a test on Friday.
Dec 13 '05 #5
me.num
means
I can't feel anything in my butt
or
I have a form with a control called num on it

I think it's not expected to be more than one value. Some dbs and db
developers might want to use DOA and some might want to use ADO so I
gave both ways;

What's being collected? The maximum num is being collected ... the kind
one feels after reading a long post from David

0 is the first. When we SELECT MAX we get just one record and that
record has just one field. It's the first field. It's the last field.
It's also the zeroeth field. Think of it as the Alpha and the Omega.
..Collect is a hidden property of recordsets (both DAO and ADO) that
returns a field's value So .Collect(0) = Fields(0).Value. This is the
fastest way, TTBOMK, of getting a field's value other than to set a
reference to the field object and to use the default member of that but
that's pretty difficult if you aren't going to set a pointer to the
recordset. If we had aliased the max field we coulda used the alias as
in
SELECT MAX(num) As MaxNum FROM mytable
then we coulda used .Collect("MaxNum")

Please untangle you? Naah ... I'm only into ropes and knots as they
pertain to canoes and hoisting my food out of the reach or carnivores.

Dec 13 '05 #6


This was Karen Hill's question:
I would like to do something like this using VBA in MS Access 2000:
Me.num = "SELECT MAX(num) FROM mytable;"
How does one do that in MS Access correctly? Aggregates in SQL are
SUM, MAX, MIN which return only one value.*


and this an answer:
Lyle Fairfield <ly***********@aim.com> wrote:: DAO
: me.num = DBEngine(0)(0).OpenRecordset("SELECT MAX(num) FROM
: mytable").Collect(0)

: ADO
: me.num = CurrentProject.Connection.Execute("SELECT MAX(num) FROM
: mytable").Collect(0)

Can someone please explain to me what's going on?
I don't understand what me.num means.
I don't understand why it's expected to be more than one value.
I don't understand what's being collected
I don't understand the 0 parameter in the answer.

Please untangle me.
--thelma
Dec 13 '05 #7
Lyle Fairfield wrote:
Please untangle you? Naah ... I'm only into ropes and knots as they
pertain to canoes and hoisting my food out of the reach or carnivores.


sorry, that's me that I want to hoist out of the reach of carnivores;
my food I want to hoist out of the reach of all the vores.

Dec 13 '05 #8
Lyle Fairfield <ly***********@aim.com> wrote:
: Thelma Lubkin wrote:

:> Lyle Fairfield <ly***********@aim.com> wrote:
: Thelma I've seen a few posts from you. They were clever and
: knowledgeable. One of these is true:

: You already knew all this and much more and were just asking to see
: where this might go, or for clarification;

: Your learning has progressed much further in some areas than others;
/\ /\
|| ||
I'll settle for this one. I did know what 'me' was, but I was
struggling with this DBEngine object, particularly after reading
the reference guide's explanation. I am trying to learn Access without
any formal foundation. My resources are limited to google--a
fantastic resource, but often it's hard to tell google what I
want to know; this group, an even more fantastic resource; and
one unfortunate book that I bought -- it assumes that all you
want to do is click buttons, and all I want to do is to write code.

My major problem is that documentation puts me right to sleep,
so I only read it after a problem has already surfaced. So,
essentially, I know nothing except the limited things that I
have had to find out to get my forms working. (I'm doing this
on a volunteer basis for a non-profit organization, and I don't
get to a computer that runs Access often enough)

I asked the dumb question because I read Access's documentation
on DBEngine and really didn't understand it. Your explanation is
dead on clear: you *do* explain things well, contrary to a
previous statement of yours, and, perhaps even more important,
your answer came in the context of a real live definite example
in front of me.

Thanks for becoming one of my personal tutors on this great
group. Thanks to all the rest of you too, if anyone else is reading.

--thelma

: I am mistaken about what I read.

: In any case there will be a test on Friday.
Dec 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Steven An | last post by:
Howdy, I need to write an update query with multiple aggregate functions. Here is an example: UPDATE t SET t.a = ( select avg(f.q) from dbo.foo f where f.p = t.y ), t.b = ( select sum(f.q)...
3
by: eddiec | last post by:
hi everyone, I have a report in an adp that uses aggregate functions in its record source and I am trying to figure out how to filter the records displayed in the report: DoCmd.OpenReport...
10
by: neb | last post by:
Dear member of the forum, Ms access has built-in aggregate function like: -Sum, Max, First, Avg, ... Is it possible to build user-defined aggregate? (if you have any clue, do not hesitate to...
6
by: Larry Menard | last post by:
Folks, I know that DB2 does not (yet?) support this, but I wonder if anyone can suggest a work-around. I've seen article...
1
by: Najib Abi Fadel | last post by:
Hi i have an ordered table of dates let's say: 1/1/2004 8/1/2004 15/1/2004 29/1/2004 5/2/2004 12/2/2004
20
by: John Salerno | last post by:
I'm starting out with this: try: if int(text) 0: return True else: self.error_message() return False except ValueError: self.error_message()
5
by: BillCo | last post by:
I just wasted a long time figuring out this and I figure if I post it might save someone some pain! Jet (DAO) will allow you to to use nested aggregate functions like building blocks, e.g.: ...
1
by: Sandro997 | last post by:
Ok. I have a bit of a dilemma here. First, please consider the following function: CREATE OR REPLACE FUNCTION recent_lab(text, labs, treatments) RETURNS float8 AS $BODY$select...
4
by: wrldruler | last post by:
Hello, First, I know it's against "Access Law" to save calculations in a table, but....I want/need to. I currently have sub-totals being calculated inside a form, using DMax, DCount, and...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.