Solved

Filter to Query

Posted on 2004-08-12
4
1,001 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
4 Comments
 
LVL 8

Expert Comment

by:arcross
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank You
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now