Filter by month and year only


A

Angelsnecropolis

I've already searched for an answer but wasn't able to find something that
helps.

I have a textbox named "Date" whose properties default value is
"=Format(Date(),"Short Date")" It displays it as mm/dd/yyyy. On this form I
have two combo boxes "cboMonth" and "cboYear" which displays all 12 months
and the years of 2008 and 2009. I'm trying to create a private sub on
"GoButton_click" to filter by Month and Year based on the critieria in the
Combo boxes.

What code can I use to create this filter? Does it require another date
column whose format is mmyyyy?

Thanks!
 
Ad

Advertisements

P

Piet Linden

I've already searched for an answer but wasn't able to find something that
helps.

I have a textbox named "Date" whose properties default value is
"=Format(Date(),"Short Date")" It displays it as mm/dd/yyyy. On this form I
have two combo boxes "cboMonth" and "cboYear" which displays all 12 months
and the years of 2008 and 2009. I'm trying to create a private sub on
"GoButton_click" to filter by Month and Year based on the critieria in the
Combo boxes.

What code can I use to create this filter? Does it require another date
column whose format is mmyyyy?

Thanks!

so did you build the filter and set the FilterOn property of your form
to True? Show us your code.... the suspense is killing us.
 
P

Paul Shapiro

First, you should change the name of your Date textbox. Date is a reserved
word, and may cause problems in code.

The condition you want is something like:
year(txtDate.value) = cboYear.value And month(txtDate.value) =
cboMonth.value

That assumes the bound column in your combo boxes is numeric (1-12 for the
months, and 2008 or 2009 for the year).
 
A

Angelsnecropolis

Well, I haven't established any code for this particular filter yet. So far
what I've done is created 2 columns on the table named Date and Date 2. Date
= the Now date and Date 2 = Now date but only as "mm yyyy" so it displays as
2/1/2009 in the table.

I just need a simple code so that when cboMonth is "Febuary" and cboYear is
"2009" it will output to txtFdate = "2/1/2009". If I can get those two combo
boxes info to combine into 1 txtbox I could work it from there.

However, I'm sure someone with more experience that myself could simply
create a filter based on those 2 combo boxes, where it converts the word
Febuary to the number 2, and combines the 2 and 2009 so that it filters just
as 2/1/2009. Does that make sense?
 
A

Angelsnecropolis

Excuse my ignorance but where would I input this condition? And thanks for
the Date name change tip.

Thanks.
 
Ad

Advertisements

A

Angelsnecropolis

Rather than having the Month field = "January" I've changed it to just the
number format of "1". Therefore, when I select the month and year it will
dispay in Fdate as 1/1/2009. Then on button click is makes Date2 = Fdate
since Date2 has its own control in the Table and filters based on that date.
It's sloppy but it works.

Think you or someone can clean it up for me? ^_^
Making something work better is always appreciated.

FDate Control Source =[cboMonth] & "/1/" [cboYear]

Here is the code I'm using now.

Private Sub Gobutton_Click()
Filter = ""
Date2.Visible = True
Date2 = Fdate
Date2.SetFocus
RunCommand acCmdFilterBySelection
txtDate.SetFocus
Date2.Visible = False
End Sub
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top