Solved

Filter to Query

Posted on 2004-08-12
4
1,007 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

632 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