Question

Dynamic Access Query - Select Specific Fields

Asked by: bick2000

Hi,

I'm trying to create a form so that we will be able to select specific information from our tables when we want it. It seems like this should be really easy. I know of a simple way to query by row (ie. setting the criteria of a field), but how do I create something that filters which fields I'm going to sort by.

Detailed example:

Our tables are set up as Products, Parts, Completed, and Forecast. For the completed and forcast tables, there are prices entered for each month, ie.(Jul06, Aug06, Sep06 - those are the columns).

I want to be able to filter the data so that when I can select that i want to view "Parts for a specific product, only completed costs in Jul06" or "Parts for specific product, completed and forecast for Jul06, Aug06, and Sep06".

Am I making any sense. I just want to be able to break it down so I get to choose what analysis I want, but I can't figure out how to create a dynamic query that only selects which fields I want.

Any help?

Thanks for any help in advance! This is pretty urgent, so I am grateful for any help or pointings in the right direction. I'm not afraid of Visual Basic... just hope i can understand it... haha thanks again!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-08-10 at 13:52:00ID21950546
Tags

access

,

dynamic

,

query

Topic

Microsoft Access Database

Participating Experts
3
Points
500
Comments
6

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

    Free Tech Articles

    1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
      It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
    2. SCCM OSD Basic troubleshooting
      SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
    3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
      This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
    4. Create a Win7 Gadget
      This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
    5. Outlook continually prompting for username and password
      There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
    6. Backup Exchange 2010 Information Store using Windows Backup
      There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

    Cloud Class Webinars

    1. Avoiding Bugs in Microsoft Access
      Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
    2. Top 10 Best New Features in Visio 2010
      Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
    3. IT Consultant Business Secrets Revealed
      Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
    4. Disaster Recovery and Business Continuity
      Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
    5. Organize Your Visio Diagrams with Containers and Lists
      Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
    6. How to Us Objects, Properties, Events and Methods in Microsoft Access
      Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

    Join the Community

    Give a Little. Get a Lot.

    Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

    Join the Community

    Answers

     

    by: jadedataPosted on 2006-08-10 at 14:01:53ID: 17291295

    Hi bick2000,
      I do forms like this for all my appliactions

      I call bind the parent form to an empty single record table that has all the fields I want to filter by

      the subform is bound to the table I will be filtering and I call this simply "subfList"

      I write a function call FilterMe() that builds an SQL string that will be applied to the subform recordsource based on the selections the user has made.

      the filtering can include any or all of the fields in the filtered table and others that can be creative in desisng

    regards,
    -jadedata-

     

    by: BPebPosted on 2006-08-10 at 16:11:53ID: 17292445

    Another way I've found useful is to create the SQL dynamically.  I have a report called Custom that when it's opened opens a form with drop-downs for specific values and textboxes for search text (Like statement).  I also let them enter a custom report header if they want.  

    Once they pick the criteria they want they click on OK.  The form has the main SQL in a variable without the Where stuff.  The code then checks each thing they could have set and builds the SQL and puts it in the tag property of the form and hides the form.  The important thing to make this work is to open the form as a dialog so that it is modal and the calling code (report) doesn't continue execution until control is returned.  

    Once control is back on the report it looks at the hidden form's tag property and pulls out the info if anything is there.  Using that it finishes the SQL and sets the reports data source with it and also the report header.  And of course it closes the hidden form.  Looks like a lot, but its very clean for your users.

    'Report Code
    Private Sub Report_Open(Cancel As Integer)
       
        DoCmd.OpenForm "dlgCustomRpt", acNormal, , , acFormEdit, acDialog
        If Forms![dlgCustomRpt].Tag <> "" Then
            Me.RecordSource = Forms![dlgCustomRpt].Tag
            If Not IsNull(Forms![dlgCustomRpt].txtRptTitle) Then
                Me.lblTitle.Caption = Forms![dlgCustomRpt].txtRptTitle
                Me.lblTitle2.Caption = Forms![dlgCustomRpt].txtRptTitle
            End If
            WhereSQL = "Release = " & Forms![dlgCustomRpt].cboRelease.Column(1) & ", "
            WhereSQL = WhereSQL & "Type = " & Forms![dlgCustomRpt].cboType.Column(1) & ", "
            WhereSQL = WhereSQL & "Status = " & Forms![dlgCustomRpt].cboStatus.Column(1) & ", "
            WhereSQL = WhereSQL & "BA = " & Forms![dlgCustomRpt].cboBA.Column(1)
            Me.lblSQL.Caption = WhereSQL
            DoCmd.ShowToolbar "Print Preview", acToolbarYes
            DoCmd.Close acForm, "dlgCustomRpt"
        Else
            DoCmd.Close acForm, "dlgCustomRpt"
            Cancel = True
        End If
       
    End Sub


    'Form Code
    Option Compare Database

    Private Const strSQLFields = "SELECT tblChangeControls.[ID], tblChangeControls.[Record Status], " _
                                 & "[tblRecord Types].RecTypeDesc, tblChangeControls.[Contact Name] AS Requestor, " _
                                 & "tblChangeControls.[BA Name], tblChangeControls.[Record Name] AS [CC Name], " _
                                 & "tblChangeControls.Description, tblChangeControls.[Target Release], " _
                                 & "tblChangeControls.[Progress/Notes], tblChangeControls.[Open Date], tblChangeControls.Update_Date, " _
                                 & "tblChangeControls.[Close Date], tblStatusCodes.StatusSort, " _
                                 & "tblProjGroup.prjgNumber, tblProjGroup.prjgName " _
                                 & "FROM ((tblChangeControls LEFT JOIN [tblRecord Types] ON tblChangeControls.Type = [tblRecord Types].RecTypeCode) " _
                                 & "LEFT JOIN tblStatusCodes ON tblChangeControls.[Record Status] = tblStatusCodes.StatusCode) LEFT JOIN tblProjGroup " _
                                 & "ON tblChangeControls.prjgID = tblProjGroup.prjgID " _
                                 & "WHERE (IIf(DateDiff('d',Date(),[Close Date])>30 Or IsNull([Close Date]),'T','F'))='T' "
                                                           
    Private Sub cmdCancel_Click()
        Me.Tag = ""
        Me.Visible = False
    End Sub

    Private Sub cmdOk_Click()
    Dim ID_No As Variant, Pos As Integer
       
        Me.Tag = strSQLFields
       
        If Len(Me.txtCC) > 0 Then
            'Clean up trailing comma
            If Right$(Me.txtCC, 1) = "," Then
                ID_No = Mid$(ID_No, 1, Len(Me.txtCC) - 1)
            End If
            Pos = InStr(Me.txtCC, ",")
            If Pos > 0 Then
                Me.Tag = Me.Tag & "AND [tblChangeControls].[ID] In (" & Me.txtCC & ") "
            Else
                Me.Tag = Me.Tag & "AND [tblChangeControls].[ID]= " & Me.txtCC & " "
            End If
        End If
        If Len(Me.txtDescription) > 0 Then
            Me.Tag = Me.Tag & "AND [tblChangeControls].[Description] Like '*" & Me.txtDescription & "*' "
        End If
        If Len(Me.txtProgress) > 0 Then
            Me.Tag = Me.Tag & "AND [tblChangeControls].[Progress/Notes] Like '*" & Me.txtProgress & "*' "
        End If
        If Me.cboRelease <> 0 Then
            Me.Tag = Me.Tag & "AND [tblChangeControls].[Target Release]= " & Me.cboRelease.Column(0) & " "
        End If
        If Me.cboStatus <> 0 Then
            Me.Tag = Me.Tag & "AND [tblStatusCodes].[StatusCode]= " & Me.cboStatus.Column(0) & " "
        End If
        If Me.cboType <> 0 Then
            Me.Tag = Me.Tag & "AND [tblRecord Types].[RecTypeCode]= " & Me.cboType.Column(0) & " "
        End If
        If Me.cboBA <> 0 Then
            Me.Tag = Me.Tag & "AND [tblChangeControls].[BA Name]= '" & Me.cboBA.Column(0) & "' "
        End If
        If Len(Me.cboRequestor) > 0 Then
            Me.Tag = Me.Tag & "AND [tblChangeControls].[Contact Name]= '" & Me.cboRequestor.Column(0) & "' "
        End If
        If Len(Me.cboProjectGroup) > 0 Then
            Me.Tag = Me.Tag & "AND [tblProjGroup].[prjgID]= " & Me.cboProjectGroup.Column(0)
        End If
        Me.Visible = False
           
    End Sub

    Private Sub cmdReset_Click()
        Me.cboBA = 0
        Me.cboRelease = 0
        Me.cboStatus = 0
        Me.cboType = 0
        Me.txtDescription = ""
        Me.txtCC = ""
        Me.txtProgress = ""
        Me.txtRptTitle = "Custom Report"
    End Sub

    Private Sub Form_Load()
        Me.cboBA = 0
        Me.cboRelease = 0
        Me.cboStatus = 0
        Me.cboType = 0
        Me.txtDescription = ""
        Me.txtCC = ""
        Me.txtProgress = ""
        Me.txtRptTitle = "Custom Report"
    End Sub

     

    by: GRayLPosted on 2006-08-10 at 18:25:09ID: 17292989

    To start with, your db design is flawed.  You should never have fields like Jul06, Aug06, Sep06, etc.

    Instead, consider:

    ProdID
    PartID
    PDate
    Price

    DB Engines go down a table at considerable speed, but really slow down when it has to 'compute' across records.  Comments?

     

    by: BPebPosted on 2006-08-10 at 19:46:57ID: 17293268

    GrayL has a good point.  You should really consider redoing you layout to take advantage of the DB, not work against it.  It's very hard to search a row, but very easy to search a column.

     

    by: bick2000Posted on 2006-08-11 at 08:27:16ID: 17296937

    Dangit, i meant to split the points... i will contact EE about that..


    I ended up taking your advice and redesigning the DB a little. I hated the Jun06, Jul06 idea, but my boss told me we only needed this thing through next year, so i did it anyway, but its too hard to work with.

    BPeb, thanks for the code - though it took some time to try and understand it, I'll def. be using parts of it in the future..

    Thanks again!

    20120131-EE-VQP-002

    3 Ways to Join

    30-Day Free Trial

    The Experts

    98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

    He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

    The Experts

    97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

    The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

    Testimonials

    "...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

    Testimonials

    "I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

    Testimonials

    "WOW! You guys have great, active, and knowledgeable people on here." moore50

    Business Clients

    Business Clients

    In the Press

    "If you’ve got a question... Experts Exchange can supply an answer.”

    In the Press

    "...an invaluable aid for both IT professionals and those who require tech support."

    In the Press

    "where IT professionals provide quick answers on just about any topic"

    Business Account Plans

    Loading Advertisement...