Solved

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

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…

809 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