473,387 Members | 1,517 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,387 software developers and data experts.

Filter Question

158 100+
I am having an error when this filter is applied:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ThisWeekFilter_Click()
  2. Me.Filter = "(Year(ProjectScheduleT.DateStart)=Year(Date()) And DatePart("ww",ProjectScheduleT.DateStart,0)=DatePart("ww",Date(),0))"
  3. Me.FilterOn = True
For some reason it works fine when I apply it directly from the filter tool on the Ribbon but when I try to use it in VBA it highlight "ww" as an error. Does anyone know why?

Thanks
Feb 5 '10 #1

✓ answered by ADezii

Try replacing the Double Quotes (") with Singles (') within the DatePart() Function:
Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "(Year(ProjectScheduleT.DateStart)=Year(Date()) And " & _
  2.             "DatePart('ww',ProjectScheduleT.DateStart,0) = DatePart('ww',Date(),0))"
  3. Me.FilterOn = True

8 3502
ADezii
8,834 Expert 8TB
Try replacing the Double Quotes (") with Singles (') within the DatePart() Function:
Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "(Year(ProjectScheduleT.DateStart)=Year(Date()) And " & _
  2.             "DatePart('ww',ProjectScheduleT.DateStart,0) = DatePart('ww',Date(),0))"
  3. Me.FilterOn = True
Feb 5 '10 #2
NeoPa
32,556 Expert Mod 16PB
See Quotes (') and Double-Quotes (") - Where and When to use them.

ADezii's advice will help as the first " at the start of "ww" is closing the string in your code, not opening a string within your string. The interpreter then finds itself dealing with ww, as something it has no knowledge of.
Feb 5 '10 #3
NeoPa
32,556 Expert Mod 16PB
Try following this advice always. It is worth doing even before you get to thinking about asking any questions. In this case the compiler would have found and reported your problem without the need for a question.
When posting any code on here please :
  1. Ensure you have Option Explicit set (See Require Variable Declaration).
  2. Try to compile it. If it doesn't compile for any reason please explain that clearly - including the error message and which line of your code it appears on. Compilation is done from the Visual Basic Editor menu - Debug \ Compile Project (Where Project is the actual name of your project).
  3. Copy your code (using the Clipboard - Cut / Copy / Paste) from your project directly into your post. Typing in code is not appreciated as it is likely to introduce typos which cause members to waste their time unnecessarily.
  4. Ensure that the code in your post is enveloped within CODE tags. The hash (#) button in the posting page helps with this. Simply select your code and click on the hash button to have it enveloped automatically.
If all these points are covered then all members will be better able to understand, and therefore attempt to answer, your question.
Feb 5 '10 #4
NeoPa
32,556 Expert Mod 16PB
I suppose I should also highlight a problem the compiler won't find for you :
Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "(Year(ProjectScheduleT.DateStart)=Year(Date()) And DatePart("ww",ProjectScheduleT.DateStart,0)=DatePart("ww",Date(),0))"
This line makes little sense as I see it, as the second must always be true if the first is. If two dates are equal, then the week values of those dates cannot help but be equal also.
Feb 5 '10 #5
jaad
158 100+
Thanks Adezii, the changing of the quotes " to ' did the trick. Much appreciated.

NEOPA: I always wondered about this "Option explicit" and "Option Compare Database" line at the top. I understand what "Option Explicit" means, but what does"Compare database" line about?
Feb 5 '10 #6
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
specifies how comparisons are made in the code. Check the Help system for full details, but basically it determines how strings should be compared. Is the case of the characters to be considered or ignored. The Database setting indicates to use the setting defined in the databse options, but you can choose to take control and set it explicitly if you prefer.
Feb 6 '10 #7
jaad
158 100+
I appreciate the feedback, thanks a million. You guys are by far the best bunch online.
Feb 6 '10 #8
NeoPa
32,556 Expert Mod 16PB
We're always glad to help when we can :)
Feb 7 '10 #9

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

Similar topics

9
by: Robin Cull | last post by:
Imagine I have a dict looking something like this: myDict = {"key 1": , "key 2": , "key 3": , "key 4": } That is, a set of keys which have a variable length list of associated values after...
1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
8
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying the filter." I have searched the newsgroups, and...
4
by: Keith | last post by:
A2003, XP Pro. I'm in the middle of designing a form to act as a custom filter, like a very basic 'filter by form'. It has two sets of combos, those on the left are to choose the field name(s)...
2
by: cefrancke | last post by:
I have a form (no underlying record set) that has two separate sub-forms on it. Each sub-form has data from two different tables. Above each sub-form there is one unbound combo box with a SQL...
2
by: AAJ | last post by:
I know this sounds nuts, but how do I remove the following filter from a Object Datasource that looks at my business layer... ODSDefaultUserProfiles.FilterExpression = "AllowedWebPage = '" +...
9
by: dee | last post by:
I'd like to filter by the following criteria: left(LeadDisposition,3) = "Sit" AND Appt_Date = Text767 I have no idea how to do this. Appreciate help.
15
by: scatterbrain | last post by:
I'm trying to create a popup form so that my peers have and easy way to filter information by 4 categories: Presenter, Evaluator, Date, or Topic. All this information is stored in my Data table and I...
3
by: Soulspike | last post by:
Form name to filter = frmSortFor Filter based on list box from frmTest= lstSortFor Form containing list box = frmTest Field (CompCodes) data format = "PM SM TS EW WA" I have a database that I...
4
by: Twayne | last post by:
Hi, I've been playing with ' if(!filter_var($email, FILTER_VALIDATE_EMAIL)) ' on my server and it seems to be working 100%. Pretty handy. Any ideas where I could find a summary of the e-mail...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.