?
Solved

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

Posted on 2014-11-22
3
Medium Priority
?
183 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 earned 2000 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
ID: 40460812
Glad to help.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

741 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