Solved

filter combo box based on current date

Posted on 2013-11-02
7
475 Views
Last Modified: 2013-11-02
I am having difficulty in trying to filter a combobox when a form opens to only show the current season. The combo box has the following set for the source:

SELECT tblSeasons.SeasonID, tblSeasons.Season, tblSeasons.SeasonStarts, tblSeasons.SeasonEnding
FROM tblSeasons
ORDER BY tblSeasons.Season;

Season is a text and SeasonStarts and SeasonEnding are dates

I wish that when the form opens that based on the current date the combo box shows 2013-2014 but takes assuming that the current date falls between SeasonStarts and SeasonEnding

How can I achieve this?
0
Comment
Question by:MGardner
[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
  • 3
  • 3
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39619096
a criteria you can use to select the value for the combo box is


where [SeasonStarts] <= Date and [SeasonEnding]>= Date


post a sample db ...
0
 
LVL 2

Author Comment

by:MGardner
ID: 39619122
Hi, I have tried this and it does filter the list but I guess I didn't correctly describe the problem. I should have said that I would like the combo box to show the current season when the form opens rather than filter the season. At least then we can still choose a different season to filter the list box on. is this achievable and how?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39619131
first you need to get the season with the filter i posted above,

dim strSeason
strSeason=dlookup("season","tblSeasons", "[SeasonStarts] <= Date and [SeasonEnding]>= Date")


then iterate thru the combo box list to find the value and set the combo box value to that...

dim j as integer
for j =0 to combo0.listcount -1
       if .itemdata(j,1)=strseason then
          me.combo0.value=.itemdata(j)
          exit for
       end if
next

upload a copy of the db..
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 61

Expert Comment

by:mbizup
ID: 39619134
Try this in your form's Current Event:

Me.MyComboName = DLookup("SeasonID","tblSeasons","SeasonStarts <= Date() AND SeasonEnding >= Date()")

Open in new window

0
 
LVL 2

Author Comment

by:MGardner
ID: 39619242
I have used the code above but seems to be falling over, it still isn't filling the list and dosn't open the form to the current season. I haves stripped down the Db which is 2011but to get to the form from the swb, click on competitions.
Camera-Club-Competion-Db.accdb
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39619276
0
 
LVL 2

Author Closing Comment

by:MGardner
ID: 39619285
That works well capricorn1 and what I was after. many thanks for the help and much appreciated
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

739 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