Solved

Filter to Query

Posted on 2004-08-12
4
1,006 Views
Last Modified: 2012-05-05
Hey All Again,

Need some more of your expert help.

From FORM, please help me figure out how I can use a command  button to transfer all the filtered FORM fields to a QUERY using VBA

Basically I want user to be able to fileter from a FORM then use a command button to transfer the filtered data to a QUERY for output or viewing


Thanks Much

Janxx


0
Comment
Question by:Montanajobs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 8

Expert Comment

by:arcross
ID: 11783689
Try this for start in your button (on click event)

Dim sSQL as string
Dim qry as DAO.querydef

sSQL = me.recordsource

Set qry = currentdb.createquerydef("MyQuery",sSQL)

0
 
LVL 39

Accepted Solution

by:
stevbe earned 500 total points
ID: 11783772
if you use a report you can pass the filter of the form in the wherecondition argument of docmd.openreport

If Me.FilterOn = True Then
    DoCmd.OpenReport ReportName:="MyReport", WhereCondition:=Me.Filter
Else
    DoCmd.OpenReport ReportName:="MyReport", WhereCondition:=Me.Filter
End If

another way to view the data woukld be to create a datsheet form (which looks just like a query) and pass the filter, again, in the WhereCondition argument.

You could also let the users switch the view of the form that is already filtered to datsheet view ... either teach them that his is available from the View menu or you could embed the form as a subform and then on the  main form add a button ...

Private Sub cmdSwitch_Click()
    DoCmd.RunCommand acCmdSubformDatasheetView
End Sub

Steve
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 11783808
transfer filtered form fields? how are the users selecting what fields to select, is it from a listbox or something

basically from your selected fields, build your sql

e.g.

sFields       'contains list of fields

sSql = "SELECT " & sFields & " FROM sometable"

create your query, like shown then use you can dump the output, say use DoCmd.SendObject

0
 

Author Comment

by:Montanajobs
ID: 11784157
Thank You
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question