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

report filter help

Hi All,

Firstly I am working in access 2010. I am trying to create an event (activated by clicking a button on a form) where by a filtered report will be opened. The form in question is bound to the table where the results will be coming from and contains an option group with three options: 1 month (value = 1), 2 months (value = 2) and 3 months (value = 3).

So we're clear the report I am trying to generate will show renewal dates within 1, 2, or 3 months from the current date.

I have the current code:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Find_record_Click()
  4. Dim strDate As Date
  5.  
  6. Select Case Me.Frame15.Value
  7. Case Is = 1
  8. strDate = DateAdd("d", 30, Now())
  9. If Me.Check24 = "0" Then
  10. Call DoCmd.OpenReport("SFIND report", acViewReport, , "Renewal Date <" & strDate)
  11. ElseIf Me.Check24 = "-1" Then
  12. Call DoCmd.OpenReport("SFIND Report2", acViewReport, , "Renewal Date <" & strDate)
  13. End If
  14. Case Is = 2
  15. strDate = DateAdd("d", 60, Now())
  16. If Me.Check24 = "0" Then
  17. Call DoCmd.OpenReport("SFIND report", acViewReport, , "Renewal Date <" & strDate)
  18. ElseIf Me.Check24 = "-1" Then
  19. Call DoCmd.OpenReport("SFIND Report2", acViewReport, , "Renewal Date <" & strDate)
  20. End If
  21. Case Is = 3
  22. strDate = DateAdd("d", 90, Now())
  23. If Me.Check24 = "0" Then
  24. Call DoCmd.OpenReport("SFIND report", acViewReport, , "Renewal Date <" & strDate)
  25. ElseIf Me.Check24 = "-1" Then
  26. Call DoCmd.OpenReport("SFIND Report2", acViewReport, , "Renewal Date <" & strDate)
  27. End If
  28. End Select
  29. End Sub
It is compiled and does work if I take out the report filter. I have also done a debug.print and it is selecting the correct case depending on which option is selected. But as soon as I put the filter in the report won't open. I feel that the answer is fairly simple but I have tried a number of times with various strings and I can't get it to work.

Thanks in advance
Feb 7 '13 #1
5 1484
TheSmileyCoder
2,322 Expert Mod 2GB
Replace
Expand|Select|Wrap|Line Numbers
  1. "Renewal Date <" & strDate)
with
Expand|Select|Wrap|Line Numbers
  1. "Renewal Date <#" & strDate & "#")
Just like " is used to indicate start and end of a string, the # is used to indicate start and end of date.

Otherwise the date:
2013-02-07 will be conceived as 2013 minus 2 minus 7.
Feb 7 '13 #2
zmbd
5,501 Expert Mod 4TB
DoCmd.OpenReport("SFIND report", acViewReport, , "Renewal Date <" & strDate)

See this last part "Renewal Date <" & strDate
this is a petpeeve of mine as it is not straight forward to troubleshoot. What you need is a string expression that's a valid SQL WHERE clause without the word WHERE. With that space in there between "Renewal" and "Date", you might be causing yourself heartburn... try
"[Renewal Date] < #" & strDate & "#"
This is one reason I never ever use spaces or anything except the underscore and alphanumerics in my field, file, and other names. You will also need the "#" for date delimination/.
Feb 7 '13 #3
Seth Schrock
2,965 Expert 2GB
It would be nice to have the error message along with the number. However, I'm going to make a guess that you need brackets around the field name in your filter. So line 10 would be:
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.OpenReport("SFIND report", acViewReport, , "[Renewal Date] <" & strDate)
I know that in a query, fields with spaces must be inside brackets and I'm almost positive that WHERE arguments to open forms or reports follows the same requirement.

For future reference, if you get an error message, always provide that in your original question along with the error number. It provides some very necessary information for those trying to help you.

Edit: And I missed (again) the # delimiter for dates. Smiley and Z probably have the answer.
Feb 7 '13 #4
zmbd
5,501 Expert Mod 4TB
hey... everyone go back to sleep here... :)
Opps... there's my timer, back to the lab!
Feb 7 '13 #5
NeoPa
32,556 Expert Mod 16PB
See these links :
How to ask "good" questions -- READ BEFORE SUBMITTING A QUESTION!.
Before Posting (VBA or SQL) Code.
Literal DateTimes and Their Delimiters (#).

Using the default format of a date is not at all recommended when putting it into a SQL string. Not only are the delimiters required, but the format is also very important.
Feb 7 '13 #6

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

Similar topics

4
by: Nathan Bloomfield | last post by:
I am using the code below to filter a report: Private Sub Set_Filter_Click() If Me! And Me! <> "" Then If Application.CurrentProject.AllReports("rptDailyOutput").IsLoaded Then DoCmd.Close...
4
by: John Galt | last post by:
I need to save a report to an RTF and I am using OutputTo acReport: DoCmd.OutputTo acReport, stDocName, acFormatRTF, TodaysDir & "-" & "Name.rtf" This command saves the report nicely, however...
2
by: Mike Sweetman | last post by:
I have a form Form1 which when the Advanced Filter/Sort is used creates a form(maybe) with a title 'Form1Filter1 : Filter'. When I apply the filter to Form1 it is applied, but the value of...
1
by: kufre | last post by:
I'm runing my report off a query and I need help filtering out two field. Each record has a Status field and Status Effective Date field. In the Status field, I have two records #6:C and PNP I want...
0
by: kolalakitty | last post by:
Hello, I'm new to using Crystal Reports and have run into a problem. I'm currently designing a new database for a company. The front end application is being coded in C# using Visual Studio.Net...
6
by: pobnospam | last post by:
I have a field called ingredients where multiple ingredients can be contained in one record (client request). Now when a report is run I need to prompt a user to determine which records to display...
7
by: fleece | last post by:
I set up a form for searching criteria and pass the searching result to a report. On this report there is an unbound text box (=.Filter) and shows the searching criteria. It works fine when searching...
2
by: Phil Stanton | last post by:
I have an address label report based on a query of names and addresses. I want to supress printing labels for those people with emails held in Fieild MemEMail so in the Filter property I put ...
0
by: Marie Gardner | last post by:
Hi, I want to create a form that filters a report that is between a date range, and includes only the data for the item selected in the combo box. For example, I am creating a time manager...
1
by: Deepak Wadhwa | last post by:
how to make report with help of D2k in oracle?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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...

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.