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: - Option Compare Database
-
-
Private Sub Find_record_Click()
-
Dim strDate As Date
-
-
Select Case Me.Frame15.Value
-
Case Is = 1
-
strDate = DateAdd("d", 30, Now())
-
If Me.Check24 = "0" Then
-
Call DoCmd.OpenReport("SFIND report", acViewReport, , "Renewal Date <" & strDate)
-
ElseIf Me.Check24 = "-1" Then
-
Call DoCmd.OpenReport("SFIND Report2", acViewReport, , "Renewal Date <" & strDate)
-
End If
-
Case Is = 2
-
strDate = DateAdd("d", 60, Now())
-
If Me.Check24 = "0" Then
-
Call DoCmd.OpenReport("SFIND report", acViewReport, , "Renewal Date <" & strDate)
-
ElseIf Me.Check24 = "-1" Then
-
Call DoCmd.OpenReport("SFIND Report2", acViewReport, , "Renewal Date <" & strDate)
-
End If
-
Case Is = 3
-
strDate = DateAdd("d", 90, Now())
-
If Me.Check24 = "0" Then
-
Call DoCmd.OpenReport("SFIND report", acViewReport, , "Renewal Date <" & strDate)
-
ElseIf Me.Check24 = "-1" Then
-
Call DoCmd.OpenReport("SFIND Report2", acViewReport, , "Renewal Date <" & strDate)
-
End If
-
End Select
-
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
5 1484
Replace - "Renewal Date <" & strDate)
with - "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.
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/.
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: - 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.
zmbd 5,501
Expert Mod 4TB
hey... everyone go back to sleep here... :)
Opps... there's my timer, back to the lab!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 ...
|
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...
|
by: Deepak Wadhwa |
last post by:
how to make report with help of D2k in oracle?
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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: 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...
| |