Solved

filter combo box based on current date

Posted on 2013-11-02
7
480 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
Independent Software Vendors: 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

623 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