Solved

filter combo box based on current date

Posted on 2013-11-02
7
465 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
  • 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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