Solved

filter combo box based on current date

Posted on 2013-11-02
7
440 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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 119

Accepted Solution

by:
Rey Obrero 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Run MS Access Module from Macro / Bat File 9 46
MS Access Bound Objects. 6 28
Error in SQL Query 36 37
DSum between dates 5 11
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…
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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