G
Guest
I've got a query that randomizes the order of entries. When I run it in
Access it works.
But I try to access it from Excel, and no matter whether I use the automatic
system that Excel has for updating database info or if I code it in VBA and
literally open the recordset, the "random" numbers ALWAYS are the same for a
given set of data (that should be reordered every time). So even though the
query has data in a different order each time when viewed in Access, the same
query when viewed through Excel is always in the same order.
I thought that perhaps accessing the query from Excel wasn't actually
running the query, but pulling existing data (which I think can't be true,
but work with me here...) but even if I run the query a couple times in
Access and they try again from Excel, the results are the same as before
running the query in Access. In other words, even if the data were static,
changing that static data doesn't solve the problem.
I've used both the following ways to access the query from Excel:
Set lRecords = lAccess.CurrentDb.OpenRecordset("Display Required")
Set lRecords = lAccess.CurrentDb.QueryDefs("Display Required").OpenRecordset
where lAccess is an Access application object. The SQL for the "Display
Required" is:
SELECT [Select Required].Field1, [Select Required].Field2, [Select
Required].Field3, [Select Required].Field4, Rnd([ID]) AS Sort
FROM [Select Required]
ORDER BY Rnd([ID]);
Again, this works in Access, just not when bringing the results to Excel.
I've even tried following the Excel OpenRecordset lines with
lRecords.Sort = "Rnd([ID])"
which is redundant, since that sort is already built into the query, but I'm
trying everything I can think of; still doesn't work.
Doing manual cut and paste from the correctly-working Access view is not a
suitable workaround.
Any ideas what's going wrong here?
Thanks!
BnB
Access it works.
But I try to access it from Excel, and no matter whether I use the automatic
system that Excel has for updating database info or if I code it in VBA and
literally open the recordset, the "random" numbers ALWAYS are the same for a
given set of data (that should be reordered every time). So even though the
query has data in a different order each time when viewed in Access, the same
query when viewed through Excel is always in the same order.
I thought that perhaps accessing the query from Excel wasn't actually
running the query, but pulling existing data (which I think can't be true,
but work with me here...) but even if I run the query a couple times in
Access and they try again from Excel, the results are the same as before
running the query in Access. In other words, even if the data were static,
changing that static data doesn't solve the problem.
I've used both the following ways to access the query from Excel:
Set lRecords = lAccess.CurrentDb.OpenRecordset("Display Required")
Set lRecords = lAccess.CurrentDb.QueryDefs("Display Required").OpenRecordset
where lAccess is an Access application object. The SQL for the "Display
Required" is:
SELECT [Select Required].Field1, [Select Required].Field2, [Select
Required].Field3, [Select Required].Field4, Rnd([ID]) AS Sort
FROM [Select Required]
ORDER BY Rnd([ID]);
Again, this works in Access, just not when bringing the results to Excel.
I've even tried following the Excel OpenRecordset lines with
lRecords.Sort = "Rnd([ID])"
which is redundant, since that sort is already built into the query, but I'm
trying everything I can think of; still doesn't work.
Doing manual cut and paste from the correctly-working Access view is not a
suitable workaround.
Any ideas what's going wrong here?
Thanks!
BnB