dbTalk Databases Forums  

Option group filter

comp.databases.ms-access comp.databases.ms-access


Discuss Option group filter in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
WhathaveIdone?
 
Posts: n/a

Default Option group filter - 10-28-2010 , 06:10 PM






I am trying to filter a subform with an option group I have on the
mainform (yes, I know a combobox is better, but this is to help people
who have less knowledge of computers). The field I am trying to filter
is a date field on the subform. Here is the code I have so far.
tblTimeCard is the table behind the subform. It appears that 3 of my 4
options are working just fine. Its calculating the week that I am
having problems with.
Option 1 = Today
Option 2 = Week
Option 3 = Month
Option 4 = Year

Dim strWhere As String
Dim LngLen as Long
Const conJetDate = "\#mm\/dd\/yyyy\#"

Select Case Me.Frame64
Case 1
strWhere = "(Year([tblTimeCard].[WorkDay]))=Year(Date()) AND
(Month([tblTimeCard].[WorkDay]))=Month(Date()) AND (Day([tblTimeCard].
[WorkDay]))=Day(Date())"

Case 2
strWhere = "(Year([tblTimeCard].[WorkDay])=Year(Date()) AND
(DatePart("ww",[tblTimeCard].[WorkDay],0)=DatePart("ww",Date(),0))"
' I may not have gotten all the parenthesis correct, but I am
assuming it is correct in my code

Case 3
strWhere = "(Year([tblTimeCard].[WorkDay]))=Year(Date()) AND
(Month([tblTimeCard].[WorkDay]))=Month(Date())"

Case 4
strWhere = "(Year([tblTimeCard].[WorkDay]))=Year(Date())"

End Select

lngLen = Len(strWhere)
strWhere = Left$(strWhere, lngLen)
Me.Time_Cards_Subform.Form.Filter = strWhere
Me.Time_Cards_Subform.Form.FilterOn = True

Like I said, it just seems to be the "Case 2" that is having the error
"Compile error: syntax error" message. Any help would be appreciated.
Thanks.

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Option group filter - 10-28-2010 , 09:18 PM






WhathaveIdone? wrote:

Quote:
I am trying to filter a subform with an option group I have on the
mainform (yes, I know a combobox is better, but this is to help people
who have less knowledge of computers). The field I am trying to filter
is a date field on the subform. Here is the code I have so far.
tblTimeCard is the table behind the subform. It appears that 3 of my 4
options are working just fine. Its calculating the week that I am
having problems with.
Option 1 = Today
Option 2 = Week
Option 3 = Month
Option 4 = Year

Dim strWhere As String
Dim LngLen as Long
Const conJetDate = "\#mm\/dd\/yyyy\#"

Select Case Me.Frame64
Case 1
strWhere = "(Year([tblTimeCard].[WorkDay]))=Year(Date()) AND
(Month([tblTimeCard].[WorkDay]))=Month(Date()) AND (Day([tblTimeCard].
[WorkDay]))=Day(Date())"

Case 2
strWhere = "(Year([tblTimeCard].[WorkDay])=Year(Date()) AND
(DatePart("ww",[tblTimeCard].[WorkDay],0)=DatePart("ww",Date(),0))"
' I may not have gotten all the parenthesis correct, but I am
assuming it is correct in my code

Case 3
strWhere = "(Year([tblTimeCard].[WorkDay]))=Year(Date()) AND
(Month([tblTimeCard].[WorkDay]))=Month(Date())"

Case 4
strWhere = "(Year([tblTimeCard].[WorkDay]))=Year(Date())"

End Select

lngLen = Len(strWhere)
strWhere = Left$(strWhere, lngLen)
Me.Time_Cards_Subform.Form.Filter = strWhere
Me.Time_Cards_Subform.Form.FilterOn = True

Like I said, it just seems to be the "Case 2" that is having the error
"Compile error: syntax error" message. Any help would be appreciated.
Thanks.

I think you are lacking another set of quotes around the ww. Ex:
strWhere = "(Year([tblTimeCard].[WorkDay])=Year(Date()) AND " & _
"(DatePart(""ww"",[tblTimeCard].[WorkDay],0)=DatePart(""ww"",Date(),0))"
Debug.Print strWhere

Reply With Quote
  #3  
Old   
WhathaveIdone?
 
Posts: n/a

Default Re: Option group filter - 10-29-2010 , 10:07 AM



On Oct 28, 8:18*pm, Salad <sa... (AT) oilandvinegar (DOT) com> wrote:
Quote:
WhathaveIdone? wrote:
I am trying to filter a subform with an option group I have on the
mainform (yes, I know a combobox is better, but this is to help people
who have less knowledge of computers). The field I am trying to filter
is a date field on the subform. Here is the code I have so far.
tblTimeCard is the table behind the subform. It appears that 3 of my 4
options are working just fine. Its calculating the week that I am
having problems with.
Option 1 = Today
Option 2 = Week
Option 3 = Month
Option 4 = Year

Dim strWhere As String
Dim LngLen as Long
Const conJetDate = "\#mm\/dd\/yyyy\#"

* * Select Case Me.Frame64
* * Case 1
* * * * strWhere = "(Year([tblTimeCard].[WorkDay]))=Year(Date()) AND
(Month([tblTimeCard].[WorkDay]))=Month(Date()) AND (Day([tblTimeCard]..
[WorkDay]))=Day(Date())"

* * Case 2
* * * * strWhere = "(Year([tblTimeCard].[WorkDay])=Year(Date()) AND
(DatePart("ww",[tblTimeCard].[WorkDay],0)=DatePart("ww",Date(),0))"
* * * *' I may not have gotten all the parenthesis correct, butI am
assuming it is correct in my code

* * Case 3
* * * * strWhere = "(Year([tblTimeCard].[WorkDay]))=Year(Date()) AND
(Month([tblTimeCard].[WorkDay]))=Month(Date())"

* * Case 4
* * * * strWhere = "(Year([tblTimeCard].[WorkDay]))=Year(Date())"

* * End Select

* * lngLen = Len(strWhere)
* * strWhere = Left$(strWhere, lngLen)
* * Me.Time_Cards_Subform.Form.Filter = strWhere
* * Me.Time_Cards_Subform.Form.FilterOn = True

Like I said, it just seems to be the "Case 2" that is having the error
"Compile error: syntax error" message. Any help would be appreciated.
Thanks.

I think you are lacking another set of quotes around the ww. *Ex:
strWhere = "(Year([tblTimeCard].[WorkDay])=Year(Date()) AND " & _
"(DatePart(""ww"",[tblTimeCard].[WorkDay],0)=DatePart(""ww"",Date(),0))"
Debug.Print strWhere
Thank you so much!!! That was it!! Perfect simple solution. None of
the examples I had seen on the DatePart function said anything about
that. Thanks again!!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.