Solved

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

Posted on 2014-11-22
3
176 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
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…

707 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

18 Experts available now in Live!

Get 1:1 Help Now