Non update recordset

R

Ray

I have the following query and it works correctly to my requirement except
non updatable recordset. Can someone advise me any way to modify it to
updatable recordset.

SELECT tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model, tblProduct.SuppliersModel, tblProduct.Description,
tblProduct.Product_AW, tblProduct.TE, tblProduct.GB, tblProduct.IB,
[DeliveryDate]-4 AS [Latest Insp Date], tblProduct.Rmk
FROM tblProduct LEFT JOIN qryFirstDeliveryDate ON tblProduct.Model =
qryFirstDeliveryDate.Model
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model;

Thanks,

Ray
 
J

John Spencer

I suspect the problem is caused by qryFirstDeliveryDate. I am guessing that
it finds the oldest date for a delivery. I suggest you also post the sql
for qryFirstDeliveryDate.

You may be able to solve your problem by using the DMin function and
dropping the qryFirstDeliveryDate completely. Perhaps the following MAY
work for you.

SELECT tblProduct.ProCat, tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
DMin("DeliveryDate","qryFirstDeliveryDate","Model=""" & Model & """") -4 as
[Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;
 
R

Ray

John,

Excellent guess!! It works using DMin function and now becomes a updatable
recordset. However, it seems DMin function is slower - it shows the data
line by line vs popping up at the same time. Is it its characteristics?

qryFirstDeliveryDate is as below:-

SELECT [Shipping data].Supplier, [Shipping data].Model, First(IIf([2nd
Confirm date] Is Not Null,[2nd Confirm date],IIf([1st Confirm date] Is Not
Null,[1st Confirm date],[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Supplier, [Shipping data].Model
ORDER BY [Shipping data].Supplier, [Shipping data].Model, First(IIf([2nd
Confirm date] Is Not Null,[2nd Confirm date],IIf([1st Confirm date] Is Not
Null,[1st Confirm date],[ODATE])));

Any suggestion on improvement?

Many thanks,

Ray


John Spencer said:
I suspect the problem is caused by qryFirstDeliveryDate. I am guessing
that it finds the oldest date for a delivery. I suggest you also post the
sql for qryFirstDeliveryDate.

You may be able to solve your problem by using the DMin function and
dropping the qryFirstDeliveryDate completely. Perhaps the following MAY
work for you.

SELECT tblProduct.ProCat, tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
DMin("DeliveryDate","qryFirstDeliveryDate","Model=""" & Model & """") -4
as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

Ray said:
I have the following query and it works correctly to my requirement except
non updatable recordset. Can someone advise me any way to modify it to
updatable recordset.

SELECT tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model, tblProduct.SuppliersModel, tblProduct.Description,
tblProduct.Product_AW, tblProduct.TE, tblProduct.GB, tblProduct.IB,
[DeliveryDate]-4 AS [Latest Insp Date], tblProduct.Rmk
FROM tblProduct LEFT JOIN qryFirstDeliveryDate ON tblProduct.Model =
qryFirstDeliveryDate.Model
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model;

Thanks,

Ray
 
J

John Spencer

Yes, DMin is always going to be slower. Since it gets continually called
for each row in your query.

Your qryFirstDeliveryDate query is using FIRST which does not mean EARLIEST
date. It more or less means the first record in the group that is
retreived.

You might try using a coordinated subquery in your query to get your
DeliveryDate. I'm guessing here, but you might try the following. Note
that I used the NZ functions in place of your IIFs. You can use you

SELECT tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
(SELECT Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st Confirm
date],
[ODATE])))
FROM [Shipping Data] as SD
WHERE SD.Model = tblProduct.Model) -4 as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE tblProduct.By="John William"
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I am making a bunch of guesses about the structure of your tables.

If you have to use the old qryFirstDeliveryDate you might be able to
increase the speed by dropping the Order By clause
SELECT [Shipping data].Model,
Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st Confirm date],
[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Model


Ray said:
John,

Excellent guess!! It works using DMin function and now becomes a
updatable recordset. However, it seems DMin function is slower - it shows
the data line by line vs popping up at the same time. Is it its
characteristics?

qryFirstDeliveryDate is as below:-

SELECT [Shipping data].Supplier, [Shipping data].Model, First(IIf([2nd
Confirm date] Is Not Null,[2nd Confirm date],IIf([1st Confirm date] Is Not
Null,[1st Confirm date],[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Supplier, [Shipping data].Model
ORDER BY [Shipping data].Supplier, [Shipping data].Model, First(IIf([2nd
Confirm date] Is Not Null,[2nd Confirm date],IIf([1st Confirm date] Is Not
Null,[1st Confirm date],[ODATE])));

Any suggestion on improvement?

Many thanks,

Ray


John Spencer said:
I suspect the problem is caused by qryFirstDeliveryDate. I am guessing
that it finds the oldest date for a delivery. I suggest you also post the
sql for qryFirstDeliveryDate.

You may be able to solve your problem by using the DMin function and
dropping the qryFirstDeliveryDate completely. Perhaps the following MAY
work for you.

SELECT tblProduct.ProCat, tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
DMin("DeliveryDate","qryFirstDeliveryDate","Model=""" & Model & """") -4
as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

Ray said:
I have the following query and it works correctly to my requirement
except non updatable recordset. Can someone advise me any way to modify
it to updatable recordset.

SELECT tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model, tblProduct.SuppliersModel, tblProduct.Description,
tblProduct.Product_AW, tblProduct.TE, tblProduct.GB, tblProduct.IB,
[DeliveryDate]-4 AS [Latest Insp Date], tblProduct.Rmk
FROM tblProduct LEFT JOIN qryFirstDeliveryDate ON tblProduct.Model =
qryFirstDeliveryDate.Model
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model;

Thanks,

Ray
 
R

Ray

John,

Thanks a million! Both are working correctly.

Regarding your kind comments on the qryFirstDeliveryDate query, I use First
together with sort key in ascending order should be equal to Min, isn't it?
However, you may be right that Min is quicker at least.

Ray


John Spencer said:
Yes, DMin is always going to be slower. Since it gets continually called
for each row in your query.

Your qryFirstDeliveryDate query is using FIRST which does not mean
EARLIEST date. It more or less means the first record in the group that
is retreived.

You might try using a coordinated subquery in your query to get your
DeliveryDate. I'm guessing here, but you might try the following. Note
that I used the NZ functions in place of your IIFs. You can use you

SELECT tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
(SELECT Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st Confirm
date],
[ODATE])))
FROM [Shipping Data] as SD
WHERE SD.Model = tblProduct.Model) -4 as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE tblProduct.By="John William"
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I am making a bunch of guesses about the structure of your tables.

If you have to use the old qryFirstDeliveryDate you might be able to
increase the speed by dropping the Order By clause
SELECT [Shipping data].Model,
Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st Confirm date],
[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Model


Ray said:
John,

Excellent guess!! It works using DMin function and now becomes a
updatable recordset. However, it seems DMin function is slower - it
shows the data line by line vs popping up at the same time. Is it its
characteristics?

qryFirstDeliveryDate is as below:-

SELECT [Shipping data].Supplier, [Shipping data].Model, First(IIf([2nd
Confirm date] Is Not Null,[2nd Confirm date],IIf([1st Confirm date] Is
Not Null,[1st Confirm date],[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Supplier, [Shipping data].Model
ORDER BY [Shipping data].Supplier, [Shipping data].Model, First(IIf([2nd
Confirm date] Is Not Null,[2nd Confirm date],IIf([1st Confirm date] Is
Not Null,[1st Confirm date],[ODATE])));

Any suggestion on improvement?

Many thanks,

Ray


John Spencer said:
I suspect the problem is caused by qryFirstDeliveryDate. I am guessing
that it finds the oldest date for a delivery. I suggest you also post
the sql for qryFirstDeliveryDate.

You may be able to solve your problem by using the DMin function and
dropping the qryFirstDeliveryDate completely. Perhaps the following MAY
work for you.

SELECT tblProduct.ProCat, tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
DMin("DeliveryDate","qryFirstDeliveryDate","Model=""" & Model & """") -4
as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I have the following query and it works correctly to my requirement
except non updatable recordset. Can someone advise me any way to modify
it to updatable recordset.

SELECT tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model, tblProduct.SuppliersModel, tblProduct.Description,
tblProduct.Product_AW, tblProduct.TE, tblProduct.GB, tblProduct.IB,
[DeliveryDate]-4 AS [Latest Insp Date], tblProduct.Rmk
FROM tblProduct LEFT JOIN qryFirstDeliveryDate ON tblProduct.Model =
qryFirstDeliveryDate.Model
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model;

Thanks,

Ray
 
J

John Spencer

No, FIRST (and Last) both return a more or less random record within the
specified group. Min returns the smallest value within the group and Max
returns the largest value with the group.

Quoting from Access Help

The First and Last functions are analogous to the MoveFirst and MoveLast
methods of a DAO Recordset object. They simply return the value of a
specified field in the first or last record, respectively, of the result set
returned by a query. Because records are usually returned in no particular
order (unless the query includes an ORDER BY clause), the records returned
by these functions will be arbitrary.

My personal experience, is that the ORDER BY clause often does not seem to
impact the value actually returned.

Ray said:
John,

Thanks a million! Both are working correctly.

Regarding your kind comments on the qryFirstDeliveryDate query, I use
First together with sort key in ascending order should be equal to Min,
isn't it? However, you may be right that Min is quicker at least.

Ray


John Spencer said:
Yes, DMin is always going to be slower. Since it gets continually called
for each row in your query.

Your qryFirstDeliveryDate query is using FIRST which does not mean
EARLIEST date. It more or less means the first record in the group that
is retreived.

You might try using a coordinated subquery in your query to get your
DeliveryDate. I'm guessing here, but you might try the following. Note
that I used the NZ functions in place of your IIFs. You can use you

SELECT tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
(SELECT Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st
Confirm date],
[ODATE])))
FROM [Shipping Data] as SD
WHERE SD.Model = tblProduct.Model) -4 as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE tblProduct.By="John William"
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I am making a bunch of guesses about the structure of your tables.

If you have to use the old qryFirstDeliveryDate you might be able to
increase the speed by dropping the Order By clause
SELECT [Shipping data].Model,
Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st Confirm date],
[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Model


Ray said:
John,

Excellent guess!! It works using DMin function and now becomes a
updatable recordset. However, it seems DMin function is slower - it
shows the data line by line vs popping up at the same time. Is it its
characteristics?

qryFirstDeliveryDate is as below:-

SELECT [Shipping data].Supplier, [Shipping data].Model, First(IIf([2nd
Confirm date] Is Not Null,[2nd Confirm date],IIf([1st Confirm date] Is
Not Null,[1st Confirm date],[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Supplier, [Shipping data].Model
ORDER BY [Shipping data].Supplier, [Shipping data].Model, First(IIf([2nd
Confirm date] Is Not Null,[2nd Confirm date],IIf([1st Confirm date] Is
Not Null,[1st Confirm date],[ODATE])));

Any suggestion on improvement?

Many thanks,

Ray


I suspect the problem is caused by qryFirstDeliveryDate. I am guessing
that it finds the oldest date for a delivery. I suggest you also post
the sql for qryFirstDeliveryDate.

You may be able to solve your problem by using the DMin function and
dropping the qryFirstDeliveryDate completely. Perhaps the following
MAY work for you.

SELECT tblProduct.ProCat, tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
DMin("DeliveryDate","qryFirstDeliveryDate","Model=""" & Model &
"""") -4 as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I have the following query and it works correctly to my requirement
except non updatable recordset. Can someone advise me any way to
modify it to updatable recordset.

SELECT tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model, tblProduct.SuppliersModel, tblProduct.Description,
tblProduct.Product_AW, tblProduct.TE, tblProduct.GB, tblProduct.IB,
[DeliveryDate]-4 AS [Latest Insp Date], tblProduct.Rmk
FROM tblProduct LEFT JOIN qryFirstDeliveryDate ON tblProduct.Model =
qryFirstDeliveryDate.Model
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model;

Thanks,

Ray
 
R

Ray

John,

Point noted. I need to study further. What is the main purpose of using
First and Last function (the result is not controllable) as I always think
they are used with sort key?

Today, I tried to replace the query with your suggested method using DMin
function and qryFirstDeliveryDate query on the database put on network. It
works very slowly - it took 40 seconds to show 8-line query result. Is
there any way to improve the speed?

I also tried the one query version and it got the result much quicker but
still non-updatable recordset. Did I miss something? It it can produce
updatable recordset and it would be acceptable solution.

Thanks,

Ray

John Spencer said:
No, FIRST (and Last) both return a more or less random record within the
specified group. Min returns the smallest value within the group and Max
returns the largest value with the group.

Quoting from Access Help

The First and Last functions are analogous to the MoveFirst and MoveLast
methods of a DAO Recordset object. They simply return the value of a
specified field in the first or last record, respectively, of the result
set returned by a query. Because records are usually returned in no
particular order (unless the query includes an ORDER BY clause), the
records returned by these functions will be arbitrary.

My personal experience, is that the ORDER BY clause often does not seem to
impact the value actually returned.

Ray said:
John,

Thanks a million! Both are working correctly.

Regarding your kind comments on the qryFirstDeliveryDate query, I use
First together with sort key in ascending order should be equal to Min,
isn't it? However, you may be right that Min is quicker at least.

Ray


John Spencer said:
Yes, DMin is always going to be slower. Since it gets continually
called for each row in your query.

Your qryFirstDeliveryDate query is using FIRST which does not mean
EARLIEST date. It more or less means the first record in the group that
is retreived.

You might try using a coordinated subquery in your query to get your
DeliveryDate. I'm guessing here, but you might try the following. Note
that I used the NZ functions in place of your IIFs. You can use you

SELECT tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
(SELECT Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st
Confirm date],
[ODATE])))
FROM [Shipping Data] as SD
WHERE SD.Model = tblProduct.Model) -4 as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE tblProduct.By="John William"
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I am making a bunch of guesses about the structure of your tables.

If you have to use the old qryFirstDeliveryDate you might be able to
increase the speed by dropping the Order By clause
SELECT [Shipping data].Model,
Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st Confirm date],
[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Model


John,

Excellent guess!! It works using DMin function and now becomes a
updatable recordset. However, it seems DMin function is slower - it
shows the data line by line vs popping up at the same time. Is it its
characteristics?

qryFirstDeliveryDate is as below:-

SELECT [Shipping data].Supplier, [Shipping data].Model, First(IIf([2nd
Confirm date] Is Not Null,[2nd Confirm date],IIf([1st Confirm date] Is
Not Null,[1st Confirm date],[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Supplier, [Shipping data].Model
ORDER BY [Shipping data].Supplier, [Shipping data].Model,
First(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],IIf([1st
Confirm date] Is Not Null,[1st Confirm date],[ODATE])));

Any suggestion on improvement?

Many thanks,

Ray


I suspect the problem is caused by qryFirstDeliveryDate. I am guessing
that it finds the oldest date for a delivery. I suggest you also post
the sql for qryFirstDeliveryDate.

You may be able to solve your problem by using the DMin function and
dropping the qryFirstDeliveryDate completely. Perhaps the following
MAY work for you.

SELECT tblProduct.ProCat, tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
DMin("DeliveryDate","qryFirstDeliveryDate","Model=""" & Model &
"""") -4 as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I have the following query and it works correctly to my requirement
except non updatable recordset. Can someone advise me any way to
modify it to updatable recordset.

SELECT tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model, tblProduct.SuppliersModel, tblProduct.Description,
tblProduct.Product_AW, tblProduct.TE, tblProduct.GB, tblProduct.IB,
[DeliveryDate]-4 AS [Latest Insp Date], tblProduct.Rmk
FROM tblProduct LEFT JOIN qryFirstDeliveryDate ON tblProduct.Model =
qryFirstDeliveryDate.Model
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model;

Thanks,

Ray
 
J

John Spencer

Ray,

Yes, the domain functions are slow. A problem with Access is that most of
the time when you use one of the SQL aggregate functions in a query, the
query becomes non-updateable.

In a very few cases, I've resorted to building a temporary table based on
the query with the aggregates and then using that in my join. The problem
with that can be keeping the data in the temporary table current.

Good luck with developing an acceptable solution.
John

Ray said:
John,

Point noted. I need to study further. What is the main purpose of using
First and Last function (the result is not controllable) as I always think
they are used with sort key?

Today, I tried to replace the query with your suggested method using DMin
function and qryFirstDeliveryDate query on the database put on network.
It works very slowly - it took 40 seconds to show 8-line query result. Is
there any way to improve the speed?

I also tried the one query version and it got the result much quicker but
still non-updatable recordset. Did I miss something? It it can produce
updatable recordset and it would be acceptable solution.

Thanks,

Ray

John Spencer said:
No, FIRST (and Last) both return a more or less random record within the
specified group. Min returns the smallest value within the group and Max
returns the largest value with the group.

Quoting from Access Help

The First and Last functions are analogous to the MoveFirst and MoveLast
methods of a DAO Recordset object. They simply return the value of a
specified field in the first or last record, respectively, of the result
set returned by a query. Because records are usually returned in no
particular order (unless the query includes an ORDER BY clause), the
records returned by these functions will be arbitrary.

My personal experience, is that the ORDER BY clause often does not seem
to impact the value actually returned.

Ray said:
John,

Thanks a million! Both are working correctly.

Regarding your kind comments on the qryFirstDeliveryDate query, I use
First together with sort key in ascending order should be equal to Min,
isn't it? However, you may be right that Min is quicker at least.

Ray


Yes, DMin is always going to be slower. Since it gets continually
called for each row in your query.

Your qryFirstDeliveryDate query is using FIRST which does not mean
EARLIEST date. It more or less means the first record in the group
that is retreived.

You might try using a coordinated subquery in your query to get your
DeliveryDate. I'm guessing here, but you might try the following.
Note that I used the NZ functions in place of your IIFs. You can use
you

SELECT tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
(SELECT Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st
Confirm date],
[ODATE])))
FROM [Shipping Data] as SD
WHERE SD.Model = tblProduct.Model) -4 as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE tblProduct.By="John William"
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I am making a bunch of guesses about the structure of your tables.

If you have to use the old qryFirstDeliveryDate you might be able to
increase the speed by dropping the Order By clause
SELECT [Shipping data].Model,
Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st Confirm date],
[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Model


John,

Excellent guess!! It works using DMin function and now becomes a
updatable recordset. However, it seems DMin function is slower - it
shows the data line by line vs popping up at the same time. Is it its
characteristics?

qryFirstDeliveryDate is as below:-

SELECT [Shipping data].Supplier, [Shipping data].Model, First(IIf([2nd
Confirm date] Is Not Null,[2nd Confirm date],IIf([1st Confirm date] Is
Not Null,[1st Confirm date],[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Supplier, [Shipping data].Model
ORDER BY [Shipping data].Supplier, [Shipping data].Model,
First(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],IIf([1st
Confirm date] Is Not Null,[1st Confirm date],[ODATE])));

Any suggestion on improvement?

Many thanks,

Ray


I suspect the problem is caused by qryFirstDeliveryDate. I am
guessing that it finds the oldest date for a delivery. I suggest you
also post the sql for qryFirstDeliveryDate.

You may be able to solve your problem by using the DMin function and
dropping the qryFirstDeliveryDate completely. Perhaps the following
MAY work for you.

SELECT tblProduct.ProCat, tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
DMin("DeliveryDate","qryFirstDeliveryDate","Model=""" & Model &
"""") -4 as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I have the following query and it works correctly to my requirement
except non updatable recordset. Can someone advise me any way to
modify it to updatable recordset.

SELECT tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model, tblProduct.SuppliersModel, tblProduct.Description,
tblProduct.Product_AW, tblProduct.TE, tblProduct.GB, tblProduct.IB,
[DeliveryDate]-4 AS [Latest Insp Date], tblProduct.Rmk
FROM tblProduct LEFT JOIN qryFirstDeliveryDate ON tblProduct.Model =
qryFirstDeliveryDate.Model
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model;

Thanks,

Ray
 
R

Ray

John,

Noted. Will do it with many thanks.

Ray

John Spencer said:
Ray,

Yes, the domain functions are slow. A problem with Access is that most of
the time when you use one of the SQL aggregate functions in a query, the
query becomes non-updateable.

In a very few cases, I've resorted to building a temporary table based on
the query with the aggregates and then using that in my join. The problem
with that can be keeping the data in the temporary table current.

Good luck with developing an acceptable solution.
John

Ray said:
John,

Point noted. I need to study further. What is the main purpose of using
First and Last function (the result is not controllable) as I always
think they are used with sort key?

Today, I tried to replace the query with your suggested method using DMin
function and qryFirstDeliveryDate query on the database put on network.
It works very slowly - it took 40 seconds to show 8-line query result.
Is there any way to improve the speed?

I also tried the one query version and it got the result much quicker but
still non-updatable recordset. Did I miss something? It it can produce
updatable recordset and it would be acceptable solution.

Thanks,

Ray

John Spencer said:
No, FIRST (and Last) both return a more or less random record within the
specified group. Min returns the smallest value within the group and
Max returns the largest value with the group.

Quoting from Access Help

The First and Last functions are analogous to the MoveFirst and MoveLast
methods of a DAO Recordset object. They simply return the value of a
specified field in the first or last record, respectively, of the result
set returned by a query. Because records are usually returned in no
particular order (unless the query includes an ORDER BY clause), the
records returned by these functions will be arbitrary.

My personal experience, is that the ORDER BY clause often does not seem
to impact the value actually returned.

John,

Thanks a million! Both are working correctly.

Regarding your kind comments on the qryFirstDeliveryDate query, I use
First together with sort key in ascending order should be equal to Min,
isn't it? However, you may be right that Min is quicker at least.

Ray


Yes, DMin is always going to be slower. Since it gets continually
called for each row in your query.

Your qryFirstDeliveryDate query is using FIRST which does not mean
EARLIEST date. It more or less means the first record in the group
that is retreived.

You might try using a coordinated subquery in your query to get your
DeliveryDate. I'm guessing here, but you might try the following.
Note that I used the NZ functions in place of your IIFs. You can use
you

SELECT tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
(SELECT Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm
date],
IIf([1st Confirm date] Is Not Null,[1st
Confirm date],
[ODATE])))
FROM [Shipping Data] as SD
WHERE SD.Model = tblProduct.Model) -4 as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE tblProduct.By="John William"
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I am making a bunch of guesses about the structure of your tables.

If you have to use the old qryFirstDeliveryDate you might be able to
increase the speed by dropping the Order By clause
SELECT [Shipping data].Model,
Min(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],
IIf([1st Confirm date] Is Not Null,[1st Confirm date],
[ODATE]))) AS DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Model


John,

Excellent guess!! It works using DMin function and now becomes a
updatable recordset. However, it seems DMin function is slower - it
shows the data line by line vs popping up at the same time. Is it
its characteristics?

qryFirstDeliveryDate is as below:-

SELECT [Shipping data].Supplier, [Shipping data].Model,
First(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],IIf([1st
Confirm date] Is Not Null,[1st Confirm date],[ODATE]))) AS
DeliveryDate
FROM [Shipping data]
GROUP BY [Shipping data].Supplier, [Shipping data].Model
ORDER BY [Shipping data].Supplier, [Shipping data].Model,
First(IIf([2nd Confirm date] Is Not Null,[2nd Confirm date],IIf([1st
Confirm date] Is Not Null,[1st Confirm date],[ODATE])));

Any suggestion on improvement?

Many thanks,

Ray


I suspect the problem is caused by qryFirstDeliveryDate. I am
guessing that it finds the oldest date for a delivery. I suggest you
also post the sql for qryFirstDeliveryDate.

You may be able to solve your problem by using the DMin function and
dropping the qryFirstDeliveryDate completely. Perhaps the following
MAY work for you.

SELECT tblProduct.ProCat, tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model,
tblProduct.SuppliersModel,
tblProduct.Description,
tblProduct.Product_AW,
tblProduct.TE, tblProduct.GB, tblProduct.IB,
DMin("DeliveryDate","qryFirstDeliveryDate","Model=""" & Model &
"""") -4 as [Latest Insp Date],
tblProduct.Rmk
FROM tblProduct
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat,
tblProduct.Supplier,
tblProduct.Brand,
tblProduct.Model;

I have the following query and it works correctly to my requirement
except non updatable recordset. Can someone advise me any way to
modify it to updatable recordset.

SELECT tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model, tblProduct.SuppliersModel,
tblProduct.Description, tblProduct.Product_AW, tblProduct.TE,
tblProduct.GB, tblProduct.IB, [DeliveryDate]-4 AS [Latest Insp
Date], tblProduct.Rmk
FROM tblProduct LEFT JOIN qryFirstDeliveryDate ON tblProduct.Model
= qryFirstDeliveryDate.Model
WHERE (((tblProduct.By)="John William"))
ORDER BY tblProduct.ProCat, tblProduct.Supplier, tblProduct.Brand,
tblProduct.Model;

Thanks,

Ray
 
Top