Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / February 2005



Tip: Looking for answers? Try searching our database.

ADO recordset  question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Clifford - 21 Feb 2005 17:26 GMT
Hello all.

This is such a basic question, but I can't find an answer.

I have a function in a class module that finds data from a series of
database tables. The data, when found, is placed into a new recordset within
the function. All OK here.
Now, where I am stuck is how do I make a query from this query?

For example, I have my new recordset in my function that contain all of the
data that I have extracted from the database tables, now I want to search
that recordset for a further sub set of data, that is where I am stuck. OK,
I could bung it all into a temporary table, but that will hit the
performance of my app. So I thought of querying the query instead

A snippet of code to illustrate follows:

'In a class module

Public Function Some_Function(strTable As String, strMedianTbl As String,
strField As String, strPast As String, sSurvey As Integer, ByVal LabID As
Long) As String

Dim NewRS As New ADODB.Recordset
Dim RsResult As New ADODB.Recordset

Dim ReagentID As Integer              'The ReagentID for that survey
Dim WHOSurvey As Integer           'The WHOSurvey for that survey

ReagentID = 0
WHOSurvey = 0

With cnNEQAS
   .Open
   .CursorLocation = adUseClient

   With NewRS.Fields    'First define the fields of the new recordset
   .Append "LabID", adInteger, 4
   .Append "Survey", adInteger, 4
   .Append "Used", adVarChar, 7
   .Append "Dev", adSingle, 7
   End With

   With NewRS
   .Open
   End With

 strSQL = "SELECT  SomeTable.Survey, SomeTable.LabID, SampleNo." & strPast
& ", SomeTable.ReagentID " _
         & "FROM SomeTable INNER JOIN WHOSampleNo ON SomeTable.Survey =
SampleNo.SurveyN " _
         & "Where (((SomeTable.LabID) = " & LabID & ") AND
((SomeTable.Survey)<= " & sSurvey & ")) " _
         & "ORDER BY SomeTable.Survey"

         rsGeneric.Open strSQL, cnNEQAS, , , adCmdText
         Set rsGeneric.ActiveConnection = Nothing
         strSQL = ""

     If rsGeneric.RecordCount > 0 Then
       With rsGeneric
          .MoveFirst
        Do While Not .EOF

          ReagentID = !ReagentID
          WHOSurvey = !Survey

  'here I save the data that matches my criteria

          If RsResult.RecordCount > 0 Then
                  With NewRS
'Push into a new recordset
                   .AddNew
                   !LabID = RsResult!LabID
                   !Survey = RsResult!Survey
                   !Dev = (Format(RsResult![Dev], "###0.00"))
                   .Update
                   .MoveNext
                 End With
                  Set RsResult = Nothing
>>>>>>>>>>ALL OK UP TO HERE<<<<<<<<<<<

 ELSE

....Some other action
.....
...
End If
Loop
etc

<<<<<<<'HERE IS WHERE I AM STUCK>>>>>>>>

'Query the recordset (NewRs) obtained from above and do something with it.

 strSQL = "SELECT TOP 6  NewRs.Survey,  NewRs.LabID,  NewRs.Ratio " _
               & "FROM NewRs " _
              & "ORDER BY NewRs.Survey ASC"
             RsResult.Open strSQL, cnNEQAS, , , adCmdText
             Set RsResult.ActiveConnection = Nothing
             strSQL = ""

Obviously, here I get an error that states that there is no table or query
called NewRS in the database
.........................

How do I query this NewRs please?

Thank you for any help that you can give me.

Best regards

David clifford
Veign - 21 Feb 2005 17:53 GMT
The best you would be able to do is use the Find or Filter methods of the
recordset - note both are limiting..

Find:
http://www.devguru.com/Technologies/ado/quickref/recordset_find.html

Filter:
http://www.devguru.com/Technologies/ado/quickref/recordset_filter.html

Signature

Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

> Hello all.
>
[quoted text clipped - 109 lines]
>
> David clifford
David Clifford - 21 Feb 2005 19:25 GMT
Hummm..thanks for that information Chris...I'm not too sure that it would
accomplish what I am looking for though. Are you saying that it would
probably be better to write the whole lot to a temp table in the first
place?

Best regards.

David Clifford

> The best you would be able to do is use the Find or Filter methods of the
> recordset - note both are limiting..
[quoted text clipped - 122 lines]
> >
> > David clifford
Veign - 21 Feb 2005 19:33 GMT
More flexibility with the ability to use SQL...

Look into the SELECT INTO statement;

I have a SQL Reference guide in my Application Dev Resource Area that show
examples of the SELECT INTO.

Signature

Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

> Hummm..thanks for that information Chris...I'm not too sure that it would
> accomplish what I am looking for though. Are you saying that it would
[quoted text clipped - 136 lines]
> > >
> > > David clifford
David Clifford - 21 Feb 2005 21:02 GMT
OK, temp table it is. I have used the Select Into statement quite a bit
before. Still, pity it can't be done more eloquently and directly from the
query recordset though. Thank you very much for your input and time.

Best reards.

David Clifford

> More flexibility with the ability to use SQL...
>
[quoted text clipped - 147 lines]
> > > >
> > > > David clifford
ld - 26 Feb 2005 04:17 GMT
What about using MSDataShaping?  Sounds like this is what you are looking for:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdms
chierarchicalcursorsdatashapingdetail.asp


Quote:
"Data shaping means building hierarchical relationships between two or more
logical entities in a query. The hierarchy can be seen in parent-child
relationships between a record of one Recordset, and one or more records
(also known as a chapter) of another Recordset."

> OK, temp table it is. I have used the Select Into statement quite a bit
> before. Still, pity it can't be done more eloquently and directly from the
[quoted text clipped - 162 lines]
> > > > >
> > > > > David clifford
ld - 26 Feb 2005 04:19 GMT
Here is an example:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdho
wdatashapingvbexample.asp


> What about using MSDataShaping?  Sounds like this is what you are looking for:
>
[quoted text clipped - 172 lines]
> > > > > >
> > > > > > David clifford
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.