Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 8th, 2005, 11:41 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I get a subset of a recordset??

Hello, I have a form where the end user enters a date, chooses the values for Me.txtCriteria, used in the

select query below, then clicks of button. The form button's onClick event has the code given below:

'select records from tblRecord corresponding to people and topic

strSQL = "SELECT (tblRecord.[Date Completed]), tblRecord.TopicID, tblRecord.PersonID FROM tblRecord "
strSQL = strSQL & "WHERE (((tblRecord.PersonID) In (" & Me.txtCriteria & ") AND ((tblRecord.TopicID)=" & Me.cboTopic & ")))"

Set rst_01 = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

'move through each row of the created recordset
Do Until rst_01.EOF
lngPersonID = rst_01.PersonID
Debug.Print "rst1", rst_01(0), rst_01(1), rst_01(2)

'here I want to get a SUBSET of rst_01 corresponding to the current value of lngPersonID,
'then evaluate each row within the subset and act according
'because I only want to append a record to rst_01 if and only if rst_01
'has NO records with Date Completed equal to the date entered on the form,
'problem is there are multiple records with the same lngPersonID value
'within rst_01

rst_01.MoveNext
Loop
rst_01.Close
Set rst_01 = Nothing

I have tried the FilterField code from Access help like so:
Set rst_02 = FilterField(rst_01, rst_01.PersonID, lngPersonID)
(I copied the function verbatim into a module.)

I don't know how to convert the above select query to an ADO query or I would try using ADO to do this...The VBA forum is closed...

Thank you, Tom
 
Old January 10th, 2005, 08:45 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Here is how I would do this:

1. Create a generic query that has the fields you need and store it as a query.

2. Create your report or form based on that generic query.

3. Use the buttons to open the form or report and pass the parameters to the form or report (actually, to the query or table behind them.)

Then use this for your button On Click Event:

'==========Code Starts==========

Dim stDocName As String
Dim sttxtCriteria As String
Dim stTopicID As String
Dim stLinkCriteria As String

sttxtCriteria = Me.txtCriteria
stTopicID = Me.cboTopic

stLinkCriteria = "[PersonID] = " & "'" & sttxtCriteria & "'" _
     & " And " & "[TopicID] = " & "'" & stTopicID & "'"

'for a form:
DoCmd.OpenForm stDocName, , , stLinkCriteria

'for a report:
DoCmd.OpenReport stDocName, acPreview, , stLink
'==========Code Ends==========

If you are using combo boxes for the criteria, you have to make sure the combo box is bound to the proper column. It has to pass the data needed for the query. So if you use the ID field in your query, bind to Column 1 in your combo box. If you use a plain text value, then bind to column 2 or the pertinent column.

I hope this helps.


mmcdonal
 
Old January 10th, 2005, 09:50 AM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you...The above-mentioned suggestion assumes the presence of stored forms, combo boxes, reports, queries, etc.

None of the above are readily available, nor are they part of the solution, because the SQL and the recordset are dynamically generated within a form button's OnClick event, as already indicated.

From a Usenet Access newsgroup, I learned that filtering the newly-created recordset on the PersonID and the Me.txtDateCompleted field (on a row-by-row basis) was the solution I needed.

This topic should be considered closed.

Thank you,
Tom






Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting subset of XML using XSLT sentah XSLT 3 September 3rd, 2008 02:44 PM
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
creating a subset of xml schema using XSLT kapar_p XSLT 8 November 21st, 2006 09:46 AM
Extracting Subset and Modifying Attribute fauster XSLT 1 September 6th, 2006 08:41 AM
using preceding-sibling in apply-templates subset rathbird XSLT 0 April 16th, 2004 10:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.