A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Subform Date Filter



 
 
Thread Tools Display Modes
  #1  
Old June 14th, 2006, 09:06 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Subform Date Filter

I have a Main Form & Subform, on the Main I have a combo Box with Date Range
criteria, This Week, Last Week... etc.
There is no parent child relationship. Is it possible to date filter the
subform from the Main form? and if so what would the statement be?


  #2  
Old June 14th, 2006, 09:40 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Subform Date Filter

On Wed, 14 Jun 2006 14:06:06 -0600, "phuser"
wrote:

I have a Main Form & Subform, on the Main I have a combo Box with Date Range
criteria, This Week, Last Week... etc.
There is no parent child relationship. Is it possible to date filter the
subform from the Main form? and if so what would the statement be?


You could base the Subform on a query referencing the combo box.
Depending on what's included in etc. you may need a VBA function, or
you might be able to use a big snarky Switch() function as the
criterion, something like

= Switch([Forms]![mainform]![cboDateRange] = "This Week",

DateAdd("d", -Weekday(Date()), Date()),
[Forms]![mainform]![cboDateRange] = "Last Week",
DateAdd("d", -7-Weekday(Date()), Date()),
etc. etc.)
AND
Switch([Forms]![mainform]![cboDateRange] = "This Week",
DateAdd("d", 7-Weekday(Date()), Date()),
[Forms]![mainform]![cboDateRange] = "Last Week",
DateAdd("d", -Weekday(Date()), Date()),
etc. etc.)

John W. Vinson[MVP]
  #3  
Old June 14th, 2006, 10:35 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Subform Date Filter

Totally friggin lost,

That didnt work for me, I added the VB code to the "On Change" for that Main
Form combo but I kept getting syntax errors, what was the "d" for ?
Dont understand what to do in the query either.

Sorry for being such a noob.


"John Vinson" wrote in message
...
On Wed, 14 Jun 2006 14:06:06 -0600, "phuser"
wrote:

I have a Main Form & Subform, on the Main I have a combo Box with Date
Range
criteria, This Week, Last Week... etc.
There is no parent child relationship. Is it possible to date filter the
subform from the Main form? and if so what would the statement be?


You could base the Subform on a query referencing the combo box.
Depending on what's included in etc. you may need a VBA function, or
you might be able to use a big snarky Switch() function as the
criterion, something like

= Switch([Forms]![mainform]![cboDateRange] = "This Week",

DateAdd("d", -Weekday(Date()), Date()),
[Forms]![mainform]![cboDateRange] = "Last Week",
DateAdd("d", -7-Weekday(Date()), Date()),
etc. etc.)
AND
Switch([Forms]![mainform]![cboDateRange] = "This Week",
DateAdd("d", 7-Weekday(Date()), Date()),
[Forms]![mainform]![cboDateRange] = "Last Week",
DateAdd("d", -Weekday(Date()), Date()),
etc. etc.)

John W. Vinson[MVP]



  #4  
Old June 14th, 2006, 11:09 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Subform Date Filter

On Wed, 14 Jun 2006 15:35:39 -0600, "phuser"
wrote:

Totally friggin lost,

That didnt work for me, I added the VB code to the "On Change" for that Main
Form combo but I kept getting syntax errors, what was the "d" for ?
Dont understand what to do in the query either.


The AfterUpdate event (as I suggested) would be better than the Change
event (which fires *at every keystroke*, not when a selection is made.

"d" means to calculate the date range in Days (rather than "m" for
Months, "h" for Hours and so on).

Please post your actual code and the error message. Can't help you if
we can't see what you're doing!

John W. Vinson[MVP]
  #5  
Old June 14th, 2006, 11:43 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Subform Date Filter

Private Sub DateFilter_AfterUpdate()

= Switch([Forms]![frmExport]![DateFilter] = "This Week",
DateAdd("d", -weekday(Date()), Date()), [Forms]![frmExport]![DateFilter] =
"Last Week", DateAdd("d", 7-weekday()), Date())) And
Switch([Forms]![frmExport]![DateFilter] = "This Week", DateAdd("d",
7-Weeday(Date()), Date()), [Forms]![frmExport]![DateFilter] = "Last Week",
DateAdd("d", -Weekday(Date()), Date()))
End Sub

"John Vinson" wrote in message
...
On Wed, 14 Jun 2006 15:35:39 -0600, "phuser"
wrote:

Totally friggin lost,

That didnt work for me, I added the VB code to the "On Change" for that
Main
Form combo but I kept getting syntax errors, what was the "d" for ?
Dont understand what to do in the query either.


The AfterUpdate event (as I suggested) would be better than the Change
event (which fires *at every keystroke*, not when a selection is made.

"d" means to calculate the date range in Days (rather than "m" for
Months, "h" for Hours and so on).

Please post your actual code and the error message. Can't help you if
we can't see what you're doing!

John W. Vinson[MVP]



  #6  
Old June 14th, 2006, 11:46 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Subform Date Filter

Sorry the Error code recieved was

Compile Error:
Expected: line number or label or statement or end of statement


"John Vinson" wrote in message
...
On Wed, 14 Jun 2006 15:35:39 -0600, "phuser"
wrote:

Totally friggin lost,

That didnt work for me, I added the VB code to the "On Change" for that
Main
Form combo but I kept getting syntax errors, what was the "d" for ?
Dont understand what to do in the query either.


The AfterUpdate event (as I suggested) would be better than the Change
event (which fires *at every keystroke*, not when a selection is made.

"d" means to calculate the date range in Days (rather than "m" for
Months, "h" for Hours and so on).

Please post your actual code and the error message. Can't help you if
we can't see what you're doing!

John W. Vinson[MVP]



 




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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Toolbars, Drop-Down Menus Rick New Users 1 September 21st, 2005 11:17 AM
filter dates and have date range in form 'green' New Users 1 May 18th, 2005 03:51 AM
Filter Report By Date Edgar Chado via AccessMonster.com Using Forms 2 May 4th, 2005 05:40 AM
How do I add a date from a form to a subform dbaggett General Discussion 2 February 5th, 2005 01:55 AM


All times are GMT +1. The time now is 01:15 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.