473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Filtering results in a subform from main form - between dates!

50
Hope you can help guys.

I have a scheduling database, the main schedule table contains the following fields:

AddedDate
Day/Night
Machine
Arm/Head
StockCode
ToolNumber
Operator
etc

I then have a continuous subform based on this table. This subform sits within the detail section of my main form titled 'frm_schedule'.

Because there are many records for each variable in the table (Can be up to 100 / day) I need to set up multiple filter combo boxes in the header of my main form. I want to set them up so that they filter the records down 'after update'.

The first i am struggling with is 'this week', here is the code I use and I keep getting syntax errors etc...

Expand|Select|Wrap|Line Numbers
  1. Private Sub DatePick_AfterUpdate()
  2.  
  3. If Me.DatePickCombo = "This Week" Then
  4.  
  5. Me.Frm_Schedule_Subform.Form.Filter = "[AddedDate] = Between #" & DateAdd("d",1-Weekday(Date(),2),Date()) & "# And #" & DateAdd("d",7-Weekday(Date(),2),Date()) & "#"
  6.  
  7. Me.Frm_Schedule_Subform.Form.FilterOn = True
  8.  
  9. Me.Form.Refresh
  10.  
  11. End If
1. Do you know what's going wrong with my code

2. In using this method I need to be able to switch individual filters off, is there an easy way of naming them so that it makes code easier the more limiters I introduce to the header of my form?

Many thanks in advance, OllyJ
Jan 18 '08 #1
6 7256
MikeTheBike
639 Expert 512MB
Hope you can help guys.

I have a scheduling database, the main schedule table contains the following fields:

AddedDate
Day/Night
Machine
Arm/Head
StockCode
ToolNumber
Operator
etc

I then have a continuous subform based on this table. This subform sits within the detail section of my main form titled 'frm_schedule'.

Because there are many records for each variable in the table (Can be up to 100 / day) I need to set up multiple filter combo boxes in the header of my main form. I want to set them up so that they filter the records down 'after update'.

The first i am struggling with is 'this week', here is the code I use and I keep getting syntax errors etc...

Expand|Select|Wrap|Line Numbers
  1. Private Sub DatePick_AfterUpdate()
  2.  
  3. If Me.DatePickCombo = "This Week" Then
  4.  
  5. Me.Frm_Schedule_Subform.Form.Filter = "[AddedDate] = Between #" & DateAdd("d",1-Weekday(Date(),2),Date()) & "# And #" & DateAdd("d",7-Weekday(Date(),2),Date()) & "#"
  6.  
  7. Me.Frm_Schedule_Subform.Form.FilterOn = True
  8.  
  9. Me.Form.Refresh
  10.  
  11. End If
1. Do you know what's going wrong with my code

2. In using this method I need to be able to switch individual filters off, is there an easy way of naming them so that it makes code easier the more limiters I introduce to the header of my form?

Many thanks in advance, OllyJ
Hi

Very quickly of the top of my head try this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub DatePick_AfterUpdate()
  2.  
  3. If Me.DatePickCombo = "This Week" Then
  4.  
  5.     Me.Frm_Schedule_Subform.Form.Filter = "[AddedDate] Between #" & Foprmat(DateAdd("d", 1 - Weekday(Date, 2), Date), "mm/dd/yy") & "# And #" & Format(DateAdd("d", 7 - Weekday(Date, 2), Date), "mm/dd/yy") & "#"
  6.  
  7.     Me.Frm_Schedule_Subform.Form.FilterOn = True
  8.  
  9. Me.Form.Refresh
  10.  
  11. End If
I have removed the '=' from before the Between and added the format function, but not sure if this is neccesarry for you, but would be for me in the UK.

MTB
Jan 18 '08 #2
OllyJ
50
Thanks Mike, tried your way but it wouldn't filter at all?

Im from UK too so i do need it that format but have already formatted the date box within the form thanks.

OllyJ
Jan 18 '08 #3
MikeTheBike
639 Expert 512MB
Thanks Mike, tried your way but it wouldn't filter at all?

Im from UK too so i do need it that format but have already formatted the date box within the form thanks.

OllyJ
Hi

A few questions.

When you say you tried my way, did you remove the '=' AND use the format function to produce US dates (NOT UK dates) ??

When you say it woudn't filter at all, do you mean it doese not now give syntax errors, but just does not return any records ?

It is not the date box on the form that needs formatting!!

On the basis that you are not now getting syntax error, may I suggest adding a msgbox as below, and see what you get!

Expand|Select|Wrap|Line Numbers
  1. Msgbox "[AddedDate] Between #" & Format(DateAdd("d", 1 - Weekday(Date, 2), Date), "mm/dd/yy") & "# And #" & Format(DateAdd("d", 7 - Weekday(Date, 2), Date), "mm/dd/yy") & "#"
  2.  
  3. Me.Frm_Schedule_Subform.Form.Filter = "[AddedDate] Between #" & Format(DateAdd("d", 1 - Weekday(Date, 2), Date), "mm/dd/yy") & "# And #" & Format(DateAdd("d", 7 - Weekday(Date, 2), Date), "mm/dd/yy") & "#"
  4.  
  5. Me.Frm_Schedule_Subform.Form.FilterOn = True
  6.  
The msgbox should display the dates in US format, ie. mm/dd/yy (not dd/mm/yy).

Let us now what happens.


MTB
Jan 20 '08 #4
OllyJ
50
MTB

I've sorted it!! Many apologies for the misunderstandings. When I went through everything again from the start it worked and limited the results to 'this week'.

Here is the code I used for anyone else who might need it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub DatePick_AfterUpdate() 
  2.  
  3. If Me.DatePick = "This Week" Then     Me.Frm_Schedule_Subform.Form.Filter = "[AddedDate] Between #" & DateAdd("d", 1 - Weekday(Date, 2), Date) & "# And #" & DateAdd("d", 7 - Weekday(Date, 2), Date) & "#"     
  4.  
  5. Me.Frm_Schedule_Subform.Form.FilterOn = True 
  6.  
  7. Me.Form.Refresh 
  8.  
  9. End If
  10.  
  11. End Sub 
There are still issues that i'm strggling with however Mike, if you or someone you know could help in any way that would be great.

My main problem with this form is that I need several filters to be running in sync' - i.e. 'This week' to be selected and then 'Days'. But the results need to show results from days, this week. When I run multiple filters it replaces the last filter with the latest one to be true?

- Is there a way of applying multiple filters based on what is selected in each combobox?

- Is there a way of naming filters so as to easily reference them within a chunk of code?

Hope you can help

OllyJ
Jan 21 '08 #5
MikeTheBike
639 Expert 512MB
MTB

I've sorted it!! Many apologies for the misunderstandings. When I went through everything again from the start it worked and limited the results to 'this week'.

Here is the code I used for anyone else who might need it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub DatePick_AfterUpdate() 
  2.  
  3. If Me.DatePick = "This Week" Then     Me.Frm_Schedule_Subform.Form.Filter = "[AddedDate] Between #" & DateAdd("d", 1 - Weekday(Date, 2), Date) & "# And #" & DateAdd("d", 7 - Weekday(Date, 2), Date) & "#"     
  4.  
  5. Me.Frm_Schedule_Subform.Form.FilterOn = True 
  6.  
  7. Me.Form.Refresh 
  8.  
  9. End If
  10.  
  11. End Sub 
There are still issues that i'm strggling with however Mike, if you or someone you know could help in any way that would be great.

My main problem with this form is that I need several filters to be running in sync' - i.e. 'This week' to be selected and then 'Days'. But the results need to show results from days, this week. When I run multiple filters it replaces the last filter with the latest one to be true?

- Is there a way of applying multiple filters based on what is selected in each combobox?

- Is there a way of naming filters so as to easily reference them within a chunk of code?

Hope you can help

OllyJ
Hi

Please you have got it working. However, if your computer is set to UK dates, I still believe you need to use the format statement I suggested (at least I have never found it works properly without) unless you have some setting I don't know about!?

The reason it works at present, I believe, is because the two date are both in January, but after the 12th. These dates (Day & Month) cannot be interpreted as any othe date. However, if the date was say 8th Jan then Access (VBA) would interpret this as 1st of August, unless you tell it otherwise. Try it and if you find any different, then please let us know.


With regard to multiple filters, well yes you can, but it involes some work.

Two ways; both use buttons to apply and reset filter(s)

1) Wite code to check the filer controls and constuct the filter as before in the button Click event; also the reset.

2) Use a stored query for the Form Record Source and connect it to the filter controls in the query designer. This method is a little move tricky as you will, no doubt, need to use the Like and the * wild card characture to cater for the Null case(s). Also you will need to devise a strategy to cater for no date range specified, if that is required (I normally use the Max & Min dates form the date field being filterd in that case - needs coding and hidden controls in the form!). This method does not stickly need buttons as you can requery the form after each filter setting, but I find continually requerying the form when setting multiple filters vaguely annoying.


HTH

MTB
Jan 21 '08 #6
OllyJ
50
Thanks for your input MTB

I have now got the date filters working by doing it through the query as a record source for the continuous subform like you said.

I am now trying to restrict the Day / Night by a textbox in the header and as you wisely spotted in advance, i need something to enter in order for there not to be a limit and both results for day and night shown...is there something that can be entered in the textbox (which is effectively the querys criteria) so as to not restrict the results?

Hope you can help again, OllyJ
Jan 22 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
5
by: Richard | last post by:
Hi, I have a form that take some time to load due to many comboboxes and at least 8 subforms. When I filter or sort the main form I get an error message and then Access shuts down. They ask if...
19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
3
by: Todd | last post by:
Hi, I've been told in another forum that I can apply a filter to a subform (from a control on the main form) by using the following code: Me.sfrMySubform.Filter = " = 7" I've tried this...
1
by: MLH | last post by:
I have a form with a subform control on it listing records returned by a saved query named UnbilledVehicles. I would like to put command buttons on the main form to apply dynamic filters to the...
2
by: Katie | last post by:
I need to store a history of two fields in two seperate tables: Event - where the key is Event_ID Stage - where the key is Stage_ID The joins are: Main Table Event Table Stage Table ...
3
by: paquer | last post by:
On my Main form I have a Command Button that opens a Subform in order to create a new Subform record. At this point I want the subform to show only the new record being created. Not all the...
2
by: franc sutherland | last post by:
Hello, I am using Access 2003. I have a query which shows a list of club meetings sorted by date. This query is displayed in continuous forms, in a subform. I would like to select a month on...
4
by: OzNet | last post by:
I have a form with a subform and I need to filter the records in the subform by dates. (Access 2007) The main form has two unbound text boxes called StartFilter and EndFilter. Both use the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.