Solved

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

Posted on 2014-11-22
3
179 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
  • 2
3 Comments
 
LVL 47

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 47

Expert Comment

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

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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…

816 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