PC Review


Reply
Thread Tools Rate Thread

Creating a recordset based on another recordset... :-(

 
 
romantercero
Guest
Posts: n/a
 
      14th Jun 2005
hi

Long Time Reader Firs time poster...

I hope some one can help me with this as I have not been able to fin
an an answer anywhere...

Ok, so I want to manipulate data on a table using various SQL queries
So I can create some temporary table and then delete them once I hav
my way with them but I thought it would be faster usin
DAO.recordsets. Generating the first one based on a table is n
proble


Dim rs1 As DAO.Recordse
Dim rs2 As DAO.Recordse

Set rs1 = CurrentDb.OpenRecordset("SELECT palletid
clave,lote,sum(pal) as pallets FROM Disponibles "

"GROUP BY palletid, clave,lote,facturacion " &
"HAVING (((Facturacion) = " & intClient
& ") AN
((Sum(disponibles.pal))>0));"


Now, generating the seccond recordset based on the first one will no
work. I get Run-Time error 3078 The MSJet DBE cannot find the inpu
table or query 'rs2'. Here's the code for that

[code:1:0a480bf3f2
Set rs2 = CurrentDb.OpenRecordset("SELECT palletid
avg(pallets) AS PalletCount FROM rs2 " &
"GROUP BY palletid;"
[/code:1:0a480bf3f2

Als
[code:1:0a480bf3f2
CantidadPallets = DSum("PalletCount"
"[rs2]"
[/code:1:0a480bf3f2
Will give me the same error. I gather that recordsets cannot be use
interchangebly with tables or queries :-

Any thoughs will be greatly apreciated

 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      14th Jun 2005
"romantercero" <(E-Mail Removed)> wrote in
message news:FLednTjD4-(E-Mail Removed)
> hi!
>
> Long Time Reader Firs time poster....
>
> I hope some one can help me with this as I have not been able to find
> an an answer anywhere....
>
> Ok, so I want to manipulate data on a table using various SQL queries.
> So I can create some temporary table and then delete them once I have
> my way with them but I thought it would be faster using
> DAO.recordsets. Generating the first one based on a table is no
> problem
>
>
>
> Dim rs1 As DAO.Recordset
> Dim rs2 As DAO.Recordset
>
>
> Set rs1 = CurrentDb.OpenRecordset("SELECT palletid,
> clave,lote,sum(pal) as pallets FROM Disponibles " &
> _
> "GROUP BY palletid, clave,lote,facturacion " & _
> "HAVING (((Facturacion) = " & intCliente
> & ") AND
> ((Sum(disponibles.pal))>0));")
>
>
>
> Now, generating the seccond recordset based on the first one will not
> work. I get Run-Time error 3078 The MSJet DBE cannot find the input
> table or query 'rs2'. Here's the code for that:
>
> [code:1:0a480bf3f2]
> Set rs2 = CurrentDb.OpenRecordset("SELECT palletid,
> avg(pallets) AS PalletCount FROM rs2 " & _
> "GROUP BY palletid;")
> [/code:1:0a480bf3f2]


That would have had to be "FROM rs1" anyway, even if it would work. But
it won't -- see below.

> Also
> [code:1:0a480bf3f2]
> CantidadPallets = DSum("PalletCount",
> "[rs2]")
> [/code:1:0a480bf3f2]
> Will give me the same error. I gather that recordsets cannot be used
> interchangebly with tables or queries :-(
>
> Any thoughs will be greatly apreciated!


No, I'm afraid that won't work. Recordsets exist in memory, but they
are not objects known to the database, so you can't use SQL or a domain
aggregate function to select from one.

If it helps, you can get the same effect by combining the SQL
statements, treating the first as a virtual table. Like this:

Set rs2 = CurrentDb.OpenRecordset( _
"SELECT T.palletid, avg(T.pallets) AS PalletCount " & _
"FROM (" & _
"SELECT palletid, clave, lote, sum(pal) as pallets " & _
"FROM Disponibles " & _
"GROUP BY palletid, clave, lote, facturacion " & _
"HAVING ((Facturacion = " & intCliente & ") AND " & _
"(Sum(disponibles.pal)>0)) " & _
") As T " & _
"GROUP BY T.palletid"

or, building on that, this:

Set rs3 = CurrentDb.OpenRecordset( _
"SELECT Sum(S.PalletCount) As CantidadPallets FROM ("
"SELECT T.palletid, avg(T.pallets) AS PalletCount " & _
"FROM (" & _
"SELECT palletid, clave, lote, sum(pal) as pallets " & _
"FROM Disponibles " & _
"GROUP BY palletid, clave, lote, facturacion " & _
"HAVING ((Facturacion = " & intCliente & ") AND " & _
"(Sum(disponibles.pal)>0)) " & _
") As T " & _
"GROUP BY T.palletid" & _
") As S"

CantidadPallets = rs3!CantidadPallets
rs3.Close

Be aware, though, that these queries are all independent of one another.
You don't need to open recordset rs1 before opening rs2, nor rs2 before
opening rs3. But neither do you get any benefit from doing so -- except
maybe you may get the benefit of some data caching on the part of the
database engine; I don't know about that.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
romantercero
Guest
Posts: n/a
 
      16th Jun 2005
Thank you for the response

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could create a new recordset based an exist recordset via SQL directly Jason Jiang Microsoft Access 13 21st Apr 2006 03:25 AM
Changing the recordset of one form based on the recordset of another form Scott Doyle Microsoft Access 1 24th Jan 2005 06:11 PM
help please...get values from recordset based on another recordset =?Utf-8?B?SmFjaw==?= Microsoft Access VBA Modules 1 5th Dec 2004 02:37 AM
Dynamically creating Subfrms based on number in recordset Michael Banks Microsoft Access Form Coding 4 21st Oct 2003 08:15 PM
recordset based on another recordset Newbie Microsoft Access Form Coding 1 16th Jul 2003 05:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:30 AM.