Accessing a forms filtered resultset in a query (1 Viewer)

clum

New member
Local time
Tomorrow, 00:02
Joined
Jul 28, 2015
Messages
3
I have a large table. I am making a form that displays the table, and allows the user to use Access' standard filters on many different fields to choose only some of the data. Then, after the user has used the filters to choose only some of the data, I want to be able to include only the resulting recordset (and not the entire original table) in various queries.

I'm not sure if there's a way I can directly reference the form's underlying recordset in a query.

I tried iterating through the entire form's recordset and dumping it into a new table, and then using that table, but this is incredibly slow on large datasets.

Here is the code I used:

Code:
CurrentDb.Execute "DELETE FROM FilteredJobs"
Dim rs As Recordset
Set rs = Search_subform.Form.RecordsetClone
rs.MoveFirst
While Not rs.EOF
    CurrentDb.Execute "INSERT INTO FilteredJobs VALUES (" & rs.Fields("JobID") & ")"
    rs.MoveNext
Wend

Is there an alternate way of doing this?
 

Ranman256

Well-known member
Local time
Today, 17:02
Joined
Apr 9, 2015
Messages
4,339
you have a continuous form showing all records
user enters data into the search boxes, then filter the records shown....

Test all controls for a possible filter then build the where clause.
Code:
 if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value
     'remove 1st And
sWhere= mid(sWhere,4)
   'just use the filter
 me.filter = sWhere
me.filterOn = true

'unclick the filter button (on menu bar) to remove it and show all records again.
 

clum

New member
Local time
Tomorrow, 00:02
Joined
Jul 28, 2015
Messages
3
you have a continuous form showing all records
user enters data into the search boxes, then filter the records shown....

Test all controls for a possible filter then build the where clause.
Code:
 if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value
     'remove 1st And
sWhere= mid(sWhere,4)
   'just use the filter
 me.filter = sWhere
me.filterOn = true

'unclick the filter button (on menu bar) to remove it and show all records again.
That's not exactly what I was looking for. The form is in Datasheet view, and I really wanted the user to be able to use all the versatile filtering options available in datasheet view.

However, you gave me an idea. I checked the Filter property of the form during runtime, and I see that it has a beautiful Where clause that I can use in a query. So thank you very much!
 

Users who are viewing this thread

Top Bottom