Solved

ms access 2k10 query include wildcards in dates and date ranges that user enters

Posted on 2014-11-22
3
182 Views
Last Modified: 2014-11-23
I have a query that drives a report that filters course ids and course dates. I would like the user to enter a course id with wildcard i.e... ASBS* to get all courses that begin with ASBS and a date range of #1/*/2010# thru #3/*/2010# for the period of jan thru march of 2010. I want the user to enter the criteria
tks
0
Comment
Question by:jsgould
[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
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40460004
So, do you want the user to enter the CourseID only, or also enter the month and year for the start and end dates of the query?

I generally use the following technique:
1.  3 textboxes: txt_CourseID, txt_StartDate, txt_EndDate
2.  A command button: cmd_Filter (name it whatever you want)
3.  In the click event of the cmd_Filter button, I build the criteria string, something like:

Private Sub cmd_Filter_Click

    Dim varCriteria as Variant

    if Len(Trim(me.txt_CourseID & " ")) > 0 then 
        varCriteria = "([CourseID] LIKE '" & Trim(me.txt_CourseID) & "*')"
    End If

    if len(Trim(me.txt_StartDate & " ")) > 0 then
        varCriteria = (varCriteria + " AND ") _
                            & "([Start_Date] >= #" & Trim(me.txt_StartDate) & "#)"
    end if

    if len(Trim(me.txt_EndDate & " ")) > 0 then
        varCriteria = (varCriteria + " AND ") _
                            & "([End_Date] <#" & DateAdd("d", 1, CDate(Trim(me.txt_StartDate))) & "#)"
    end if

    me.Filter = varCriteria
    me.FilterOn = LEN(varCriteria & "") > 0

End Sub

Open in new window

0
 

Author Closing Comment

by:jsgould
ID: 40460725
Thanks for the quick response!
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 40460812
Glad to help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

726 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