Solved

filter combo box based on current date

Posted on 2013-11-02
7
456 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

813 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

19 Experts available now in Live!

Get 1:1 Help Now